diff --git a/force_bdss/tests/probe_classes/mco.py b/force_bdss/tests/probe_classes/mco.py index 0c76d20491b0c67e207473853a87dd52e038fd1c..905b03cf2e93af290c20d667e6917257d54deccf 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 8a9c0538329d7d691c0284d5bedffbb4225b7fed..1af399477cc1547eef2134401eb4f73daab83403 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.'),) + + +