Skip to content
Snippets Groups Projects
Commit be9184f6 authored by Stefano Borini's avatar Stefano Borini Committed by GitHub
Browse files

Merge pull request #60 from force-h2020/move-parameters-to-mco

Moved parameters into MCO
parents eb61bec5 c747d084
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,9 @@ class DummyMCOBundle(BaseMCOBundle):
def create_communicator(self):
pass
def parameter_factories(self):
return []
class TestBaseMCOBundle(unittest.TestCase):
def test_initialization(self):
......
......@@ -2,11 +2,11 @@
"version": "1",
"workflow": {
"mco": {
"id": "force.bdss.bundle.enthought.dummy_dakota",
"id": "force.bdss.enthought.bundle.dummy_dakota",
"model_data": {
"parameters" : [
{
"id": "force.bdss.mco_parameter.enthought.ranged",
"id": "force.bdss.enthought.bundle.dummy_dakota.parameter.ranged",
"model_data": {
"initial_value": 3,
"lower_bound": 0,
......@@ -18,7 +18,7 @@
},
"data_sources": [
{
"id": "force.bdss.bundle.enthought.csv_extractor",
"id": "force.bdss.enthought.bundle.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -27,7 +27,7 @@
}
},
{
"id": "force.bdss.bundle.enthought.csv_extractor",
"id": "force.bdss.enthought.bundle.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
......@@ -38,7 +38,7 @@
],
"kpi_calculators": [
{
"id": "force.bdss.bundle.enthought.kpi_adder",
"id": "force.bdss.enthought.bundle.kpi_adder",
"model_data": {
"cuba_type_in": "PRESSURE",
"cuba_type_out": "TOTAL_PRESSURE"
......
......@@ -2,7 +2,9 @@ import unittest
from force_bdss.base_extension_plugin import (
BaseExtensionPlugin)
from force_bdss.ids import bundle_id
from force_bdss.ids import bundle_id, mco_parameter_id
from force_bdss.mco.parameters.base_mco_parameter_factory import \
BaseMCOParameterFactory
try:
import mock
......@@ -33,8 +35,17 @@ class TestBundleRegistry(unittest.TestCase):
class MySuperPlugin(BaseExtensionPlugin):
def _mco_bundles_default(self):
return [mock.Mock(spec=IMCOBundle,
id=bundle_id("enthought", "mco1"))]
return [
mock.Mock(
spec=IMCOBundle,
id=bundle_id("enthought", "mco1"),
parameter_factories=mock.Mock(return_value=[
mock.Mock(
spec=BaseMCOParameterFactory,
id=mco_parameter_id("enthought", "mco1", "ranged")
)
]),
)]
def _data_source_bundles_default(self):
return [mock.Mock(spec=IDataSourceBundle,
......@@ -64,8 +75,10 @@ class TestBundleRegistryWithContent(unittest.TestCase):
self.assertEqual(len(self.plugin.kpi_calculator_bundles), 3)
def test_lookup(self):
id = bundle_id("enthought", "mco1")
self.assertEqual(self.plugin.mco_bundle_by_id(id).id, id)
mco_id = bundle_id("enthought", "mco1")
parameter_id = mco_parameter_id("enthought", "mco1", "ranged")
self.assertEqual(self.plugin.mco_bundle_by_id(mco_id).id, mco_id)
self.plugin.mco_parameter_factory_by_id(mco_id, parameter_id)
for entry in ["ds1", "ds2"]:
id = bundle_id("enthought", entry)
......@@ -76,6 +89,31 @@ class TestBundleRegistryWithContent(unittest.TestCase):
self.assertEqual(self.plugin.kpi_calculator_bundle_by_id(id).id,
id)
with self.assertRaises(KeyError):
self.plugin.mco_bundle_by_id(
bundle_id("enthought", "foo"))
with self.assertRaises(KeyError):
self.plugin.mco_parameter_factory_by_id(
mco_id,
mco_parameter_id("enthought", "mco1", "foo")
)
with self.assertRaises(KeyError):
self.plugin.data_source_bundle_by_id(
bundle_id("enthought", "foo")
)
with self.assertRaises(KeyError):
self.plugin.data_source_bundle_by_id(
bundle_id("enthought", "foo")
)
with self.assertRaises(KeyError):
self.plugin.kpi_calculator_bundle_by_id(
bundle_id("enthought", "foo")
)
if __name__ == '__main__':
unittest.main()
import unittest
from traits.api import Float
from force_bdss.bundle_registry_plugin import BundleRegistryPlugin
from force_bdss.data_sources.base_data_source import BaseDataSource
from force_bdss.data_sources.base_data_source_bundle import \
BaseDataSourceBundle
from force_bdss.data_sources.base_data_source_model import BaseDataSourceModel
from force_bdss.ids import mco_parameter_id, bundle_id
from force_bdss.kpi.base_kpi_calculator import BaseKPICalculator
from force_bdss.kpi.base_kpi_calculator_bundle import BaseKPICalculatorBundle
from force_bdss.kpi.base_kpi_calculator_model import BaseKPICalculatorModel
......@@ -12,6 +13,9 @@ from force_bdss.mco.base_mco import BaseMCO
from force_bdss.mco.base_mco_bundle import BaseMCOBundle
from force_bdss.mco.base_mco_communicator import BaseMCOCommunicator
from force_bdss.mco.base_mco_model import BaseMCOModel
from force_bdss.mco.parameters.base_mco_parameter import BaseMCOParameter
from force_bdss.mco.parameters.base_mco_parameter_factory import \
BaseMCOParameterFactory
from force_bdss.tests import fixtures
try:
......@@ -33,6 +37,17 @@ class NullMCO(BaseMCO):
pass
class NullParameter(BaseMCOParameter):
initial_value = Float()
lower_bound = Float()
upper_bound = Float()
class NullParameterFactory(BaseMCOParameterFactory):
id = mco_parameter_id("enthought", "dummy_dakota", "ranged")
model_class = NullParameter
class NullMCOCommunicator(BaseMCOCommunicator):
def send_to_mco(self, model, kpi_results):
pass
......@@ -42,6 +57,8 @@ class NullMCOCommunicator(BaseMCOCommunicator):
class NullMCOBundle(BaseMCOBundle):
id = bundle_id("enthought", "dummy_dakota")
def create_model(self, model_data=None):
return NullMCOModel(self)
......@@ -51,6 +68,9 @@ class NullMCOBundle(BaseMCOBundle):
def create_optimizer(self):
return NullMCO(self)
def parameter_factories(self):
return [NullParameterFactory(self)]
class NullKPICalculatorModel(BaseKPICalculatorModel):
pass
......@@ -88,6 +108,8 @@ class NullDataSourceBundle(BaseDataSourceBundle):
def mock_bundle_registry_plugin():
bundle_registry_plugin = mock.Mock(spec=BundleRegistryPlugin)
bundle_registry_plugin.mco_bundles = [
NullMCOBundle(bundle_registry_plugin)]
bundle_registry_plugin.mco_bundle_by_id = mock.Mock(
return_value=NullMCOBundle(bundle_registry_plugin))
bundle_registry_plugin.kpi_calculator_bundle_by_id = mock.Mock(
......
......@@ -6,7 +6,7 @@ from force_bdss.ids import bundle_id, plugin_id
class TestIdGenerators(unittest.TestCase):
def test_bundle_id(self):
self.assertEqual(bundle_id("foo", "bar"),
"force.bdss.bundle.foo.bar")
"force.bdss.foo.bundle.bar")
for bad_entry in ["", None, " ", "foo bar"]:
with self.assertRaises(ValueError):
......@@ -15,7 +15,7 @@ class TestIdGenerators(unittest.TestCase):
bundle_id("foo", bad_entry)
def test_plugin_id(self):
self.assertEqual(plugin_id("foo", "bar"), "force.bdss.plugin.foo.bar")
self.assertEqual(plugin_id("foo", "bar"), "force.bdss.foo.plugin.bar")
for bad_entry in ["", None, " ", "foo bar"]:
with self.assertRaises(ValueError):
......
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