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

Fixed more tests for test_core_evaluation_driver

parent d57d8007
No related branches found
No related tags found
1 merge request!130Safer plugin import - 2
......@@ -88,7 +88,8 @@ class FactoryRegistryPlugin(Plugin):
if ds.id == id:
return ds
raise KeyError(id)
raise KeyError("Unable to find data source factory with id {} "
"in the registry".format(id))
def mco_factory_by_id(self, id):
"""Finds a given Multi Criteria Optimizer (MCO) factory by means of
......@@ -108,7 +109,8 @@ class FactoryRegistryPlugin(Plugin):
if mco.id == id:
return mco
raise KeyError(id)
raise KeyError("Unable to find mco factory "
"with id {} in the registry.".format(id))
def mco_parameter_factory_by_id(self, mco_id, parameter_id):
"""Retrieves the MCO parameter factory for a given MCO id and
......@@ -136,7 +138,8 @@ class FactoryRegistryPlugin(Plugin):
if factory.id == parameter_id:
return factory
raise KeyError(parameter_id)
raise KeyError("Unable to find parameter factory with id {} "
"in the registry.".format(parameter_id))
def notification_listener_factory_by_id(self, id):
"""Finds a given notification listener by means of its id.
......@@ -156,4 +159,5 @@ class FactoryRegistryPlugin(Plugin):
if nl.id == id:
return nl
raise KeyError(id)
raise KeyError("Unable to find notification listener factory "
"with id {} in the registry".format(id))
......@@ -2,7 +2,7 @@
"version": "1",
"workflow": {
"mco": {
"id": "force.bdss.enthought.factory.test_mco",
"id": "force.bdss.enthought.plugin.test.v0.factory.test_mco",
"model_data": {
"parameters" : [
]
......@@ -11,7 +11,7 @@
"execution_layers": [
[
{
"id": "force.bdss.enthought.factory.test_ds",
"id": "force.bdss.enthought.plugin.test.v0.factory.test_ds",
"model_data": {
"input_slot_info": [
],
......@@ -21,20 +21,9 @@
}
]
],
"kpi_calculators": [
{
"id": "force.bdss.enthought.factory.test_kpic",
"model_data": {
"input_slot_info": [
],
"output_slot_info": [
]
}
}
],
"notification_listeners": [
{
"id": "force.bdss.enthought.factory.test_nl",
"id": "force.bdss.enthought.plugin.test.v0.factory.test_nl",
"model_data": {
}
}
......
......@@ -33,10 +33,11 @@ from force_bdss.core_evaluation_driver import (
class TestCoreEvaluationDriver(unittest.TestCase):
def setUp(self):
self.factory_registry_plugin = ProbeFactoryRegistryPlugin()
self.registry = ProbeFactoryRegistryPlugin()
self.plugin = self.registry.plugin
application = mock.Mock(spec=Application)
application.get_plugin = mock.Mock(
return_value=self.factory_registry_plugin
return_value=self.registry
)
application.workflow_filepath = fixtures.get("test_null.json")
self.mock_application = application
......@@ -48,10 +49,8 @@ class TestCoreEvaluationDriver(unittest.TestCase):
driver.application_started()
def test_error_for_non_matching_mco_parameters(self):
mco_factories = self.factory_registry_plugin.mco_factories
mco_factories[0] = ProbeMCOFactory(
None,
nb_output_data_values=1)
mco_factory = self.registry.mco_factories[0]
mco_factory.nb_output_data_values=1
driver = CoreEvaluationDriver(
application=self.mock_application)
with testfixtures.LogCapture():
......@@ -62,16 +61,12 @@ class TestCoreEvaluationDriver(unittest.TestCase):
driver.application_started()
def test_error_for_incorrect_output_slots(self):
data_source_factories = \
self.factory_registry_plugin.data_source_factories
def run(self, *args, **kwargs):
return [DataValue()]
data_source_factories[0] = ProbeDataSourceFactory(
None,
run_function=run)
driver = CoreEvaluationDriver(
application=self.mock_application)
ds_factory = self.registry.data_source_factories[0]
ds_factory.run_function = run
driver = CoreEvaluationDriver(application=self.mock_application)
with testfixtures.LogCapture():
with six.assertRaisesRegex(
self,
......@@ -82,15 +77,13 @@ class TestCoreEvaluationDriver(unittest.TestCase):
driver.application_started()
def test_error_for_missing_ds_output_names(self):
data_source_factories = \
self.factory_registry_plugin.data_source_factories
def run(self, *args, **kwargs):
return [DataValue()]
data_source_factories[0] = ProbeDataSourceFactory(
None,
run_function=run,
output_slots_size=1)
ds_factory = self.registry.data_source_factories[0]
ds_factory.run_function = run
ds_factory.output_slots_size = 1
driver = CoreEvaluationDriver(
application=self.mock_application,
)
......@@ -161,11 +154,11 @@ class TestCoreEvaluationDriver(unittest.TestCase):
def run(self, *args, **kwargs):
return [DataValue(value=1), DataValue(value=2), DataValue(value=3)]
ds_factory = ProbeDataSourceFactory(
None,
input_slots_size=2,
output_slots_size=3,
run_function=run)
ds_factory = self.registry.data_source_factories[0]
ds_factory.input_slots_size = 2
ds_factory.output_slots_size = 3
ds_factory.run_function = run
evaluator_model = ds_factory.create_model()
evaluator_model.input_slot_info = [
......@@ -215,7 +208,7 @@ class TestCoreEvaluationDriver(unittest.TestCase):
return [DataValue(value=(first+second))]
adder_factory = ProbeDataSourceFactory(
None,
self.plugin,
input_slots_size=2,
output_slots_size=1,
run_function=adder)
......@@ -226,7 +219,7 @@ class TestCoreEvaluationDriver(unittest.TestCase):
return [DataValue(value=(first*second))]
multiplier_factory = ProbeDataSourceFactory(
None,
self.plugin,
input_slots_size=2,
output_slots_size=1,
run_function=multiplier)
......@@ -297,7 +290,3 @@ class TestCoreEvaluationDriver(unittest.TestCase):
self.assertEqual(len(kpi_results), 1)
self.assertEqual(kpi_results[0].value, 8750)
def test_empty_slot_name_skips_data_value(self):
"""Checks if leaving a slot name empty will skip the data value
in the final output
"""
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