Skip to content
Snippets Groups Projects
Commit 976a1f88 authored by Stefano Borini's avatar Stefano Borini
Browse files

Reintroduced execution and fixed a bug when no MCO is defined

parent 5cd52acd
No related branches found
No related tags found
1 merge request!101Create probe classes for tests
import unittest
import subprocess
import os
from contextlib import contextmanager
from force_bdss.tests import fixtures
@contextmanager
def cd(dir):
cwd = os.getcwd()
os.chdir(dir)
try:
yield
finally:
os.chdir(cwd)
def fixture_dir():
return os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"fixtures")
class TestExecution(unittest.TestCase):
def test_plain_invocation_mco(self):
with cd(fixtures.dirpath()):
out = subprocess.check_call(["force_bdss", "test_empty.json"])
self.assertEqual(out, 0)
def test_plain_invocation_evaluate(self):
with cd(fixtures.dirpath()):
proc = subprocess.Popen([
"force_bdss", "--evaluate", "test_empty.json"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
proc.communicate(b"1")
retcode = proc.wait()
self.assertEqual(retcode, 0)
def test_unsupported_file_input(self):
with cd(fixtures.dirpath()):
with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call(["force_bdss", "test_csv_v2.json"])
def test_corrupted_file_input(self):
with cd(fixtures.dirpath()):
with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call(["force_bdss",
"test_csv_corrupted.json"])
if __name__ == '__main__':
unittest.main()
......@@ -30,6 +30,10 @@ class CoreEvaluationDriver(BaseCoreDriver):
sys.exit(1)
mco_model = workflow.mco
if mco_model is None:
print("No MCO defined. Nothing to do. Exiting.")
sys.exit(0)
mco_factory = mco_model.factory
mco_communicator = mco_factory.create_communicator()
......
......@@ -48,6 +48,10 @@ class CoreMCODriver(BaseCoreDriver):
sys.exit(1)
mco_model = workflow.mco
if mco_model is None:
print("No MCO defined. Nothing to do. Exiting.")
sys.exit(0)
mco_factory = mco_model.factory
return mco_factory.create_optimizer()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment