def test_get_logger(self): ema_logging._logger = None logger = ema_logging.get_logger() self.assertEqual(logger, logging.getLogger(ema_logging.LOGGER_NAME)) self.assertEqual(len(logger.handlers), 1) self.assertEqual(type(logger.handlers[0]), ema_logging.NullHandler) logger = ema_logging.get_logger() self.assertEqual(logger, logging.getLogger(ema_logging.LOGGER_NAME)) self.assertEqual(len(logger.handlers), 1) self.assertEqual(type(logger.handlers[0]), ema_logging.NullHandler)
def test_engine_logger(self, mocked_application, mocked_adapter): logger = ema_logging.get_logger() mocked_logger = mock.Mock(spec=logger) mocked_logger.handlers = [] mocked_logger.manager = mock.Mock(spec=logging.Manager) mocked_logger.manager.disable = 0 ema_logging._logger = mocked_logger mocked_application.instance.return_value = mocked_application mocked_application.log = mocked_logger # no handlers ema.set_engine_logger() logger = ema_logging._logger # self.assertTrue(type(logger) == type(mocked_adapter)) mocked_logger.setLevel.assert_called_once_with(ema_logging.DEBUG) mocked_adapter.assert_called_with(mocked_logger, ema.SUBTOPIC) # with handlers mocked_logger = mock.create_autospec(logging.Logger) # ipyparallel. # mock_engine_handler = mock.create_autospec(ipyparallel.log.EnginePUBHandler) mocked_logger.handlers = [] #[mock_engine_handler] mocked_application.instance.return_value = mocked_application mocked_application.log = mocked_logger ema.set_engine_logger() logger = ema_logging._logger # self.assertTrue(type(logger) == ema.EngingeLoggerAdapter) mocked_logger.setLevel.assert_called_once_with(ema_logging.DEBUG) mocked_adapter.assert_called_with(mocked_logger, ema.SUBTOPIC)
def setUpClass(cls): logger = ema_logging.get_logger() mocked_logger = mock.Mock(spec=logger) mocked_logger.handlers = [] ema_logging._logger = mocked_logger cls.client = ipyparallel.Client(profile='default') cls.url = 'tcp://{}:20202'.format(localhost()) cls.watcher = ema.start_logwatcher(cls.url)