class test_LogMixin(Case): def setup(self): self.log = Log('Log', Mock()) self.logger = self.log.logger def test_debug(self): self.log.debug('debug') self.logger.log.assert_called_with(logging.DEBUG, 'Log - debug') def test_info(self): self.log.info('info') self.logger.log.assert_called_with(logging.INFO, 'Log - info') def test_warning(self): self.log.warn('warning') self.logger.log.assert_called_with(logging.WARN, 'Log - warning') def test_error(self): self.log.error('error', exc_info='exc') self.logger.log.assert_called_with( logging.ERROR, 'Log - error', exc_info='exc', ) def test_critical(self): self.log.critical('crit', exc_info='exc') self.logger.log.assert_called_with( logging.CRITICAL, 'Log - crit', exc_info='exc', ) def test_error_when_DISABLE_TRACEBACKS(self): from kombu import log log.DISABLE_TRACEBACKS = True try: self.log.error('error') self.logger.log.assert_called_with(logging.ERROR, 'Log - error') finally: log.DISABLE_TRACEBACKS = False def test_get_loglevel(self): self.assertEqual(self.log.get_loglevel('DEBUG'), logging.DEBUG) self.assertEqual(self.log.get_loglevel('ERROR'), logging.ERROR) self.assertEqual(self.log.get_loglevel(logging.INFO), logging.INFO) def test_is_enabled_for(self): self.logger.isEnabledFor.return_value = True self.assertTrue(self.log.is_enabled_for('DEBUG')) self.logger.isEnabledFor.assert_called_with(logging.DEBUG) def test_LogMixin_get_logger(self): self.assertIs(LogMixin().get_logger(), logging.getLogger('LogMixin')) def test_Log_get_logger(self): self.assertIs(Log('test_Log').get_logger(), logging.getLogger('test_Log')) def test_log_when_not_enabled(self): self.logger.isEnabledFor.return_value = False self.log.debug('debug') self.assertFalse(self.logger.log.called) def test_log_with_format(self): self.log.debug('Host %r removed', 'example.com') self.logger.log.assert_called_with( logging.DEBUG, 'Log - Host %s removed', ANY, ) self.assertEqual( self.logger.log.call_args[0][2].strip('u'), "'example.com'", )
class test_LogMixin(Case): def setUp(self): self.log = Log('Log', Mock()) self.logger = self.log.logger def test_debug(self): self.log.debug('debug') self.logger.log.assert_called_with(logging.DEBUG, 'Log - debug') def test_info(self): self.log.info('info') self.logger.log.assert_called_with(logging.INFO, 'Log - info') def test_warning(self): self.log.warn('warning') self.logger.log.assert_called_with(logging.WARN, 'Log - warning') def test_error(self): self.log.error('error', exc_info='exc') self.logger.log.assert_called_with( logging.ERROR, 'Log - error', exc_info='exc', ) def test_critical(self): self.log.critical('crit', exc_info='exc') self.logger.log.assert_called_with( logging.CRITICAL, 'Log - crit', exc_info='exc', ) def test_error_when_DISABLE_TRACEBACKS(self): from kombu import log log.DISABLE_TRACEBACKS = True try: self.log.error('error') self.logger.log.assert_called_with(logging.ERROR, 'Log - error') finally: log.DISABLE_TRACEBACKS = False def test_get_loglevel(self): self.assertEqual(self.log.get_loglevel('DEBUG'), logging.DEBUG) self.assertEqual(self.log.get_loglevel('ERROR'), logging.ERROR) self.assertEqual(self.log.get_loglevel(logging.INFO), logging.INFO) def test_is_enabled_for(self): self.logger.isEnabledFor.return_value = True self.assertTrue(self.log.is_enabled_for('DEBUG')) self.logger.isEnabledFor.assert_called_with(logging.DEBUG) def test_LogMixin_get_logger(self): self.assertIs(LogMixin().get_logger(), logging.getLogger('LogMixin')) def test_Log_get_logger(self): self.assertIs(Log('test_Log').get_logger(), logging.getLogger('test_Log')) def test_log_when_not_enabled(self): self.logger.isEnabledFor.return_value = False self.log.debug('debug') self.assertFalse(self.logger.log.called) def test_log_with_format(self): self.log.debug('Host %r removed', 'example.com') self.logger.log.assert_called_with( logging.DEBUG, 'Log - Host %s removed', "'example.com'", )