def test_cleanup_err(self, mock_cmd): with LogCapture() as capture: main.Harbinger().clean_up(mock_cmd, 0, 'test err') capture.check( # mock_cmd.__class__.__name__ will be 'MagicMock' ('harbinger.main', 'DEBUG', 'Cleaning Up MagicMock'), ('harbinger.main', 'ERROR', 'Encountered Error: test err'), )
def test_configure_logging(self, mock_run): harbinger = main.Harbinger() # This is a hack... def run(self, options): self.options = mock.Mock() self.options.verbose_level = options mock_run.side_effect = run harbinger.run(harbinger, 2) # pylint: disable=too-many-function-args harbinger.configure_logging() root_logger = consoleLogging.getLogger('') self.assertEqual(root_logger.handlers[1].level, consoleLogging.DEBUG) pass
def test_main_class_init(self, mock_init, mock_command_manager_class): mock_command_manager_class.return_value = 'mock command' mock_load_commands = mock.Mock() def init_side_effect(mock_self, **kwargs): expected_kwargs = { 'command_manager': 'mock command', 'deferred_help': True, 'description': 'Manager for Data Plane Testing Frameworks', 'version': 'version' } self.assertDictEqual(kwargs, expected_kwargs) mock_command_manager = mock.Mock(load_commands=mock_load_commands) mock_self.command_manager = mock_command_manager mock_init.side_effect = init_side_effect main.Harbinger() mock_command_manager_class.assert_called_once_with( 'harbinger.commands')
def test_prepare_to_run_command(self, mock_cmd): main.Harbinger().prepare_to_run_command(mock_cmd)
def test_cleanup_noerr(self, mock_cmd): with LogCapture() as capture: main.Harbinger().clean_up(mock_cmd, 0, None) capture.check( # mock_cmd.__class__.__name__ will be 'MagicMock' ('harbinger.main', 'DEBUG', 'Cleaning Up MagicMock'), )
def test_initialize_app(self): main.Harbinger().initialize_app('')