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

Fixed tests and silenced noisy one

parent 5e01dbb5
No related branches found
No related tags found
1 merge request!187Propagate data values in MCO events
......@@ -64,7 +64,8 @@ class CoreMCODriver(BaseCoreDriver):
finally:
self._deliver_finish_event()
sys.exit(1 if error else 0)
if error:
sys.exit(1)
@on_trait_change("application:stopping")
def application_stopping(self):
......
from __future__ import unicode_literals
import unittest
import testfixtures
try:
import mock
except ImportError:
......@@ -25,7 +26,8 @@ class TestBaseExtensionPlugin(unittest.TestCase):
def test_exception(self):
with mock.patch.object(ProbeExtensionPlugin, "get_name") \
as mock_get_name:
as mock_get_name, \
testfixtures.LogCapture():
mock_get_name.side_effect = Exception("Boom")
plugin = ProbeExtensionPlugin()
......
import unittest
from testfixtures import LogCapture
from force_bdss.core.data_value import DataValue
from force_bdss.tests.probe_classes.factory_registry_plugin import \
ProbeFactoryRegistryPlugin
from force_bdss.core_driver_events import (
......@@ -55,7 +56,7 @@ class TestCoreMCODriver(unittest.TestCase):
application=self.mock_application,
)
listener = driver.listeners[0]
driver.mco.started = True
driver._deliver_start_event()
self.assertIsInstance(listener.deliver_call_args[0][0], MCOStartEvent)
def test_finished_event_handling(self):
......@@ -63,7 +64,7 @@ class TestCoreMCODriver(unittest.TestCase):
application=self.mock_application,
)
listener = driver.listeners[0]
driver.mco.finished = True
driver._deliver_finish_event()
self.assertIsInstance(listener.deliver_call_args[0][0], MCOFinishEvent)
def test_progress_event_handling(self):
......@@ -71,12 +72,22 @@ class TestCoreMCODriver(unittest.TestCase):
application=self.mock_application,
)
listener = driver.listeners[0]
driver.mco.new_data = {'input': (1, 2), 'output': (3, 4)}
driver.mco.notify_new_point(
[DataValue(value=1), DataValue(value=2)],
[DataValue(value=3), DataValue(value=4)],
[0.5, 0.5])
self.assertIsInstance(
listener.deliver_call_args[0][0],
MCOProgressEvent)
self.assertEqual(listener.deliver_call_args[0][0].input, (1, 2))
self.assertEqual(listener.deliver_call_args[0][0].output, (3, 4))
event = listener.deliver_call_args[0][0]
self.assertEqual(event.optimal_point[0].value, 1)
self.assertEqual(event.optimal_point[1].value, 2)
self.assertEqual(event.optimal_kpis[0].value, 3)
self.assertEqual(event.optimal_kpis[1].value, 4)
self.assertEqual(event.weights[0], 0.5)
self.assertEqual(event.weights[0], 0.5)
def test_listener_init_exception(self):
driver = CoreMCODriver(
......@@ -106,7 +117,7 @@ class TestCoreMCODriver(unittest.TestCase):
listener = driver.listeners[0]
listener.deliver_function = raise_exception
with LogCapture() as capture:
driver.mco.started = True
driver._deliver_start_event()
self.assertTrue(listener.deliver_called)
capture.check(
......
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