From 976a1f8860a7662ae347dbfe6cdae0c37dc7b063 Mon Sep 17 00:00:00 2001
From: Stefano Borini <sborini@enthought.com>
Date: Thu, 24 Aug 2017 18:08:08 +0100
Subject: [PATCH] Reintroduced execution and fixed a bug when no MCO is defined

---
 force_bdss/cli/tests/test_execution.py | 54 ++++++++++++++++++++++++++
 force_bdss/core_evaluation_driver.py   |  4 ++
 force_bdss/core_mco_driver.py          |  4 ++
 3 files changed, 62 insertions(+)
 create mode 100644 force_bdss/cli/tests/test_execution.py

diff --git a/force_bdss/cli/tests/test_execution.py b/force_bdss/cli/tests/test_execution.py
new file mode 100644
index 0000000..3fbf57f
--- /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 f0347cf..33fc475 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 fb41714..478499a 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()
 
-- 
GitLab