From 0b743ec560194595a23a876dfc0a7efcfa255261 Mon Sep 17 00:00:00 2001
From: Stefano Borini <sborini@enthought.com>
Date: Tue, 22 May 2018 10:27:42 +0100
Subject: [PATCH] coverage

---
 force_bdss/tests/probe_classes/mco.py    | 10 ++++++--
 force_bdss/tests/test_core_mco_driver.py | 30 ++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/force_bdss/tests/probe_classes/mco.py b/force_bdss/tests/probe_classes/mco.py
index 0c76d20..905b03c 100644
--- a/force_bdss/tests/probe_classes/mco.py
+++ b/force_bdss/tests/probe_classes/mco.py
@@ -1,4 +1,4 @@
-from traits.api import Bool, Int, Function
+from traits.api import Bool, Int, Function, Any
 
 from force_bdss.core.data_value import DataValue
 from force_bdss.api import (
@@ -71,6 +71,12 @@ class ProbeMCOFactory(BaseMCOFactory):
     raises_on_create_optimizer = Bool(False)
     raises_on_create_communicator = Bool(False)
 
+    optimizer = Any()
+
+    def __init__(self, *args, **kwargs):
+        super(ProbeMCOFactory, self).__init__(*args, **kwargs)
+        self.optimizer = self.optimizer_class(self)
+
     def get_identifier(self):
         return "probe_mco"
 
@@ -107,7 +113,7 @@ class ProbeMCOFactory(BaseMCOFactory):
         if self.raises_on_create_optimizer:
             raise Exception("ProbeMCOFactory.create_optimizer")
 
-        return self.optimizer_class(self)
+        return self.optimizer
 
     def parameter_factories(self):
         return [ProbeParameterFactory(mco_factory=self)]
diff --git a/force_bdss/tests/test_core_mco_driver.py b/force_bdss/tests/test_core_mco_driver.py
index 8a9c053..1af3994 100644
--- a/force_bdss/tests/test_core_mco_driver.py
+++ b/force_bdss/tests/test_core_mco_driver.py
@@ -175,3 +175,33 @@ class TestCoreMCODriver(unittest.TestCase):
                            "'force.bdss.enthought.plugin.test.v0'. "
                            "An exception was raised. This might "
                            'indicate a programming error in the plugin.'),)
+
+        with LogCapture() as capture:
+            with self.assertRaises(SystemExit):
+                driver.application_started()
+
+    def test_mco_run_exception(self):
+        def run_func(*args, **kwargs):
+            raise Exception("run_func")
+
+        driver = CoreMCODriver(
+            application=self.mock_application,
+        )
+        registry = self.factory_registry_plugin
+        mco_factory = registry.mco_factories[0]
+        mco_factory.optimizer.run_function = run_func
+
+        with LogCapture() as capture:
+            with self.assertRaises(SystemExit):
+                driver.application_started()
+            capture.check(('force_bdss.core_mco_driver',
+                           'ERROR',
+                           'Method run() of MCO with id '
+                           "'force.bdss.enthought.plugin.test.v0"
+                           ".factory.probe_mco' from plugin "
+                           "'force.bdss.enthought.plugin.test.v0'"
+                           " raised exception. This might indicate "
+                           'a programming error in the plugin.'),)
+
+
+
-- 
GitLab