def _test_init_with_log_value(self, debug, result_level):
joined_path = 'baz'
folder = 'foo'
filename = 'bar'
console_format = '[%(levelname)s] %(message)s'
file_format = '[%(name)s][%(levelname)s][%(asctime)s] %(message)s'
with mock.patch('logging.handlers.RotatingFileHandler') as mock_fh:
with mock.patch('logging.StreamHandler') as mock_sh:
with mock.patch('logging.Formatter') as mock_formatter:
with mock.patch('os.path.join',
return_value=joined_path) as mock_join:
log_config = LogConfiguration(folder, filename, debug)
mock_sh().setLevel.assert_called_once_with(
result_level)
mock_sh().setFormatter.assert_called_once_with(
mock_formatter())
mock_fh.assert_called_once_with(joined_path,
maxBytes=1024 * 1024,
backupCount=20)
mock_fh().setLevel.assert_called_once_with(
logging.DEBUG)
mock_fh().setFormatter.assert_called_once_with(
mock_formatter())
mock_formatter.assert_has_calls([
mock.call(console_format),
mock.call(file_format)
])
mock_join.assert_called_once_with(folder, 'logs',
'%s.log' % filename)
self.assertEqual(log_config._consoleLogger, mock_sh())
self.assertEqual(log_config.console_logger, mock_sh())
self.assertEqual(log_config._fileLogger, mock_fh())
self.assertEqual(log_config.file_logger, mock_fh())
return log_config
TestLogConfiguration.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录