diff --git a/force_bdss/cli/tests/test_execution.py b/force_bdss/cli/tests/test_execution.py new file mode 100644 index 0000000000000000000000000000000000000000..3fbf57fb179b41dea4232cacd0067a89562288f6 --- /dev/null +++ b/force_bdss/cli/tests/test_execution.py @@ -0,0 +1,54 @@ +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() diff --git a/force_bdss/core_evaluation_driver.py b/force_bdss/core_evaluation_driver.py index f0347cff034a10ea8fe54339a9ce41048507fff9..33fc4755a456ad4c0609b0365c643e8f844641a5 100644 --- a/force_bdss/core_evaluation_driver.py +++ b/force_bdss/core_evaluation_driver.py @@ -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() diff --git a/force_bdss/core_mco_driver.py b/force_bdss/core_mco_driver.py index fb4171427dadcf58e98b7342fef214b6fd375df4..478499af138b50ee6ecdd1abe0ca95e583d37e85 100644 --- a/force_bdss/core_mco_driver.py +++ b/force_bdss/core_mco_driver.py @@ -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()