diff --git a/force_bdss/tests/test_core_mco_driver.py b/force_bdss/tests/test_core_mco_driver.py index fce493d9e82bf77afdd812da68b40b25530144c4..9cb92b8134227a6442d2ffa72706a0d334e2024f 100644 --- a/force_bdss/tests/test_core_mco_driver.py +++ b/force_bdss/tests/test_core_mco_driver.py @@ -1,4 +1,5 @@ import unittest +from testfixtures import LogCapture from force_bdss.mco.events import MCOStartEvent from force_bdss.tests import fixtures @@ -31,6 +32,13 @@ class TestCoreMCODriver(unittest.TestCase): ) driver.application_started() + def test_stopping(self): + driver = CoreMCODriver( + application=self.mock_application, + ) + driver.application_started() + driver.application_stopping() + def test_listeners(self): driver = CoreMCODriver( application=self.mock_application, @@ -41,4 +49,46 @@ class TestCoreMCODriver(unittest.TestCase): driver = CoreMCODriver( application=self.mock_application, ) - driver.mco.event = MCOStartEvent() + listener = driver.listeners[0] + mock_deliver = mock.Mock() + listener.__dict__["deliver"] = mock_deliver + event = MCOStartEvent() + driver.mco.event = event + self.assertTrue(mock_deliver.call_args[0][0], event) + + def test_listener_initialization_exception(self): + driver = CoreMCODriver( + application=self.mock_application, + ) + listener = driver.listeners[0] + mock_deliver = mock.Mock() + listener.__dict__["deliver"] = mock_deliver + mock_deliver.side_effect = Exception() + with LogCapture() as capture: + driver.mco.event = MCOStartEvent() + self.assertTrue(mock_deliver.called) + + capture.check( + ("force_bdss.core_mco_driver", + "ERROR", + "Exception while delivering to listener " + "NullNotificationListener: ")) + + def test_finalize_error(self): + driver = CoreMCODriver( + application=self.mock_application, + ) + driver.application_started() + + listener = driver.listeners[0] + mock_finalize = mock.Mock() + listener.__dict__["finalize"] = mock_finalize + mock_finalize.side_effect = Exception() + + with LogCapture() as capture: + driver.application_stopping() + capture.check( + ("force_bdss.core_mco_driver", + "ERROR", + "Exception while finalizing listener " + "NullNotificationListener: "))