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

Fixed tests and incorrect import of class type via string

parent 75765b67
No related branches found
No related tags found
1 merge request!114Introduces fast declaration style for factory
from envisage.api import Plugin from envisage.api import Plugin
from traits.api import Interface, String, Instance, Type from traits.api import Interface, String, Instance, Type
from force_bdss.data_sources.base_data_source import BaseDataSource
from force_bdss.data_sources.base_data_source_model import BaseDataSourceModel
class IDataSourceFactory(Interface): class IDataSourceFactory(Interface):
"""Envisage required interface for the BaseDataSourceFactory. """Envisage required interface for the BaseDataSourceFactory.
...@@ -15,9 +12,13 @@ class IDataSourceFactory(Interface): ...@@ -15,9 +12,13 @@ class IDataSourceFactory(Interface):
name = String() name = String()
data_source_class = Type(BaseDataSource) data_source_class = Type(
"force_bdss.data_sources.base_data_source.BaseDataSource"
)
model_class = Type(BaseDataSourceModel) model_class = Type(
"force_bdss.data_sources.base_data_source_model.BaseDataSourceModel"
)
plugin = Instance(Plugin) plugin = Instance(Plugin)
......
from traits.api import Interface, String, Instance, Type from traits.api import Interface, String, Instance, Type
from envisage.plugin import Plugin from envisage.plugin import Plugin
from force_bdss.kpi.base_kpi_calculator import BaseKPICalculator
from force_bdss.kpi.base_kpi_calculator_model import BaseKPICalculatorModel
class IKPICalculatorFactory(Interface): class IKPICalculatorFactory(Interface):
"""Envisage required interface for the BaseKPICalculatorFactory. """Envisage required interface for the BaseKPICalculatorFactory.
...@@ -15,9 +12,13 @@ class IKPICalculatorFactory(Interface): ...@@ -15,9 +12,13 @@ class IKPICalculatorFactory(Interface):
name = String() name = String()
kpi_calculator_class = Type(BaseKPICalculator) kpi_calculator_class = Type(
"force_bdss.kpi.base_kpi_calculator.BaseKPICalculator"
)
model_class = Type(BaseKPICalculatorModel) model_class = Type(
"force_bdss.kpi.base_kpi_calculator_model.BaseKPICalculatorModel"
)
plugin = Instance(Plugin) plugin = Instance(Plugin)
......
from traits.api import Interface, String, Instance, Type from traits.api import Interface, String, Instance, Type
from envisage.plugin import Plugin from envisage.plugin import Plugin
from force_bdss.mco.base_mco import BaseMCO
from force_bdss.mco.base_mco_communicator import BaseMCOCommunicator
from force_bdss.mco.base_mco_model import BaseMCOModel
class IMCOFactory(Interface): class IMCOFactory(Interface):
"""Interface for the BaseMCOFactory. """Interface for the BaseMCOFactory.
...@@ -16,11 +12,17 @@ class IMCOFactory(Interface): ...@@ -16,11 +12,17 @@ class IMCOFactory(Interface):
name = String() name = String()
optimizer_class = Type(BaseMCO) optimizer_class = Type(
"force_bdss.mco.base_mco.BaseMCO"
)
model_class = Type(BaseMCOModel) model_class = Type(
"force_bdss.mco.base_mco_communicator.BaseMCOCommunicator"
)
communicator_class = Type(BaseMCOCommunicator) communicator_class = Type(
"force_bdss.mco.base_mco_model.BaseMCOModel"
)
plugin = Instance(Plugin) plugin = Instance(Plugin)
......
from traits.api import HasStrictTraits, String, Type, Instance from traits.api import HasStrictTraits, String, Type, Instance
from ..base_mco_factory import BaseMCOFactory
class BaseMCOParameterFactory(HasStrictTraits): class BaseMCOParameterFactory(HasStrictTraits):
"""Factory that produces the model instance of a given BASEMCOParameter """Factory that produces the model instance of a given BASEMCOParameter
...@@ -13,7 +11,7 @@ class BaseMCOParameterFactory(HasStrictTraits): ...@@ -13,7 +11,7 @@ class BaseMCOParameterFactory(HasStrictTraits):
""" """
#: A reference to the MCO factory this parameter factory lives in. #: A reference to the MCO factory this parameter factory lives in.
mco_factory = Instance(BaseMCOFactory) mco_factory = Instance('force_bdss.mco.base_mco_factory.BaseMCOFactory')
#: A unique string identifying the parameter #: A unique string identifying the parameter
id = String() id = String()
...@@ -25,7 +23,9 @@ class BaseMCOParameterFactory(HasStrictTraits): ...@@ -25,7 +23,9 @@ class BaseMCOParameterFactory(HasStrictTraits):
description = String("Undefined parameter") description = String("Undefined parameter")
# The model class to instantiate when create_model is called. # The model class to instantiate when create_model is called.
model_class = Type('BaseMCOParameter') model_class = Type(
"force_bdss.mco.parameters.base_mco_parameter.BaseMCOParameter"
)
def __init__(self, mco_factory, *args, **kwargs): def __init__(self, mco_factory, *args, **kwargs):
self.mco_factory = mco_factory self.mco_factory = mco_factory
......
import unittest import unittest
from envisage.plugin import Plugin
from force_bdss.mco.base_mco_factory import BaseMCOFactory from force_bdss.mco.base_mco_factory import BaseMCOFactory
try: try:
...@@ -25,9 +27,14 @@ class DummyMCOParameterFactory(BaseMCOParameterFactory): ...@@ -25,9 +27,14 @@ class DummyMCOParameterFactory(BaseMCOParameterFactory):
model_class = DummyMCOParameter model_class = DummyMCOParameter
class DummyMCOFactory(BaseMCOFactory):
pass
class TestBaseMCOParameterFactory(unittest.TestCase): class TestBaseMCOParameterFactory(unittest.TestCase):
def test_initialization(self): def test_initialization(self):
factory = DummyMCOParameterFactory(mock.Mock(spec=BaseMCOFactory)) factory = DummyMCOParameterFactory(
mco_factory=BaseMCOFactory(plugin=mock.Mock(spec=Plugin)))
model = factory.create_model({"x": 42}) model = factory.create_model({"x": 42})
self.assertIsInstance(model, DummyMCOParameter) self.assertIsInstance(model, DummyMCOParameter)
self.assertEqual(model.x, 42) self.assertEqual(model.x, 42)
......
from traits.api import Interface, String, Instance from traits.api import Interface, String, Instance, Type
from envisage.plugin import Plugin from envisage.plugin import Plugin
from force_bdss.notification_listeners.base_notification_listener import \
BaseNotificationListener
from force_bdss.notification_listeners.base_notification_listener_model \
import \
BaseNotificationListenerModel
class INotificationListenerFactory(Interface): class INotificationListenerFactory(Interface):
"""Envisage required interface for the BaseNotificationListenerFactory. """Envisage required interface for the BaseNotificationListenerFactory.
...@@ -18,9 +12,15 @@ class INotificationListenerFactory(Interface): ...@@ -18,9 +12,15 @@ class INotificationListenerFactory(Interface):
name = String() name = String()
listener_class = Instance(BaseNotificationListener) listener_class = Type(
"force_bdss.notification_listeners"
".base_notification_listener.BaseNotificationListener"
)
model_class = Instance(BaseNotificationListenerModel) model_class = Type(
"force_bdss.notification_listeners"
".base_notification_listener_model.BaseNotificationListenerModel"
)
plugin = Instance(Plugin) plugin = Instance(Plugin)
......
from traits.api import Interface, String, Instance from traits.api import Interface, String, Instance, Type
from envisage.plugin import Plugin from envisage.plugin import Plugin
from force_bdss.ui_hooks.base_ui_hooks_manager import BaseUIHooksManager
class IUIHooksFactory(Interface): class IUIHooksFactory(Interface):
"""Envisage required interface for the BaseUIHooksFactory. """Envisage required interface for the BaseUIHooksFactory.
...@@ -14,7 +12,9 @@ class IUIHooksFactory(Interface): ...@@ -14,7 +12,9 @@ class IUIHooksFactory(Interface):
name = String() name = String()
ui_hooks_manager_class = Instance(BaseUIHooksManager) ui_hooks_manager_class = Type(
"force_bdss.ui_hooks.base_ui_hooks_manager.BaseUIHooksManager"
)
plugin = Instance(Plugin) plugin = Instance(Plugin)
......
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