From dbb8757ae9dbede89070b68c87055b586a0dc502 Mon Sep 17 00:00:00 2001 From: Stefano Borini <sborini@enthought.com> Date: Thu, 10 Aug 2017 19:05:02 +0100 Subject: [PATCH] Coverage --- force_bdss/tests/test_core_mco_driver.py | 52 +++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/force_bdss/tests/test_core_mco_driver.py b/force_bdss/tests/test_core_mco_driver.py index fce493d..9cb92b8 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: ")) -- GitLab