def test_line_profile_stats_decorator_no_module(self, capsys, caplog): delogger.decorators.line_profile._can_line_profiler = False mock = LineProfilerMock() _delogger = Delogger("line_profile_stats_decorator_no_module") _delogger.load_modes(StreamDebugMode()) _delogger.load_decorators(LineProfileStats()) logger = _delogger.get_logger() mock.assert_not_called() @logger.add_line_profile def test_func(arg1, arg2=None): return True # Only execute ret = test_func("testarg", 123) assert ret mock.assert_not_called() mock.add_function.assert_not_called() mock.runcall.assert_not_called() mock.print_stats.assert_not_called() logger.print_stats() mock.print_stats.assert_not_called() delogger.decorators.line_profile._can_line_profiler = True
def test_slack_token_mode_info(self): delogger = Delogger("slack_mode_info") delogger.load_modes(SlackTokenMode("slack_token", "channel")) logger = delogger.get_logger() self.execute_log(logger) assert urllib.request.urlopen.call_count == 4
def test_slack_webhook_mode_warning(self): delogger = Delogger("slack_webhook_mode_warning") delogger.load_modes(SlackWebhookMode("http://dummy??", WARNING)) logger = delogger.get_logger() self.execute_log(logger) assert urllib.request.urlopen.call_count == 3
def test_stream_color_debug_mode(self, capsys): delogger = Delogger(name="stream_color_debug_mode") delogger.load_modes(StreamColorDebugMode()) logger = delogger.get_logger() self.execute_log(logger) self.check_debug_stream_log(logger, capsys, is_color=True) Assert._bool(not Path(self.OUTPUT_DIRPATH).is_dir())
def test_stream_info_mode(self, capsys): delogger = Delogger("stream_info_mode") delogger.load_modes(StreamInfoMode()) logger = delogger.get_logger() self.execute_log(logger) self.check_normal_stream_log(logger, capsys, is_color=False) Assert._bool(not Path(self.OUTPUT_DIRPATH).is_dir())
def test_memory_profile_decorator(self, capsys, caplog): _delogger = Delogger("memory_profile_decorator") _delogger.load_modes(StreamDebugMode()) _delogger.load_decorators(MemoryProfile()) logger = _delogger.get_logger() @logger.memory_profile def test_func(arg1, arg2=None): return True # Only execute ret = test_func("testarg", 123) assert ret
def test_timed_rotating_file_mode(self, capsys): timed_file_mode = TimedRotatingFileMode() delogger = Delogger("timed_rotating_file_mode") delogger.load_modes(timed_file_mode) logger = delogger.get_logger() logfile = timed_file_mode.logfile self.execute_log(logger) self.check_log_file(logfile.filepath) Assert._bool(logfile.filepath.exists()) logfile.filepath.unlink() logfile.filepath.parent.rmdir()
def test_count_rotation_mode(self, capsys): count_rotation_mode = CountRotatingFileMode() delogger = Delogger("count_rotationg_file_mode") delogger.load_modes(count_rotation_mode) logger = delogger.get_logger() logfile = count_rotation_mode.logfile self.execute_log(logger) self.check_log_file(logfile.filepath) Assert._bool(logfile.filepath.exists()) logfile.filepath.unlink() logfile.filepath.parent.rmdir()
def test_debug_log_decorator(self, capsys, caplog): delogger = Delogger("debug_log_decorator") delogger.load_modes(StreamDebugMode()) delogger.load_decorators(DebugLog()) logger = delogger.get_logger() @logger.debuglog def test_func(arg1, arg2=None): return True ret = test_func("testarg", 123) streams = [ r"START TestDebugLogDecorator.test_debug_log_decorator.<locals>.test_func args=\('testarg', 123\) kwargs={}", r"END TestDebugLogDecorator.test_debug_log_decorator.<locals>.test_func return=None", ] self.check_decorator(logger, capsys, streams) assert ret
def test_line_memory_profile_decorator_no_module(self, capsys, caplog): delogger.decorators.line_memory_profile._can_line_profiler = False delogger.decorators.line_memory_profile._can_memory_profiler = False mock = LineProfilerMock() _delogger = Delogger("line_memory_profile_decorator") _delogger.load_modes(StreamDebugMode()) _delogger.load_decorators(LineMemoryProfile()) logger = _delogger.get_logger() @logger.line_memory_profile def test_func(arg1, arg2=None): return True # Only execute ret = test_func("testarg", 123) assert ret delogger.decorators.line_memory_profile._can_line_profiler = True delogger.decorators.line_memory_profile._can_memory_profiler = True
def test_line_profile_decorator(self): mock = LineProfilerMock() _delogger = Delogger("line_profile_decorator") _delogger.load_modes(StreamDebugMode()) _delogger.load_decorators(LineProfile()) logger = _delogger.get_logger() mock.assert_not_called() @logger.line_profile def test_func(arg1, arg2=None): return True # Only execute ret = test_func("testarg", 123) assert ret mock.assert_called_once() mock.add_function.assert_called_once() mock.runcall.assert_called_once() mock.print_stats.assert_called_once()
from delogger import Delogger from delogger.decorators.debug_log import DebugLog from delogger.modes.file import CountRotatingFileMode from delogger.modes.stream import StreamColorDebugMode if __name__ == "__main__": delogger = Delogger() delogger.load_modes(StreamColorDebugMode(), CountRotatingFileMode()) delogger.load_decorators(DebugLog()) logger = delogger.get_logger() logger.debug("debug") logger.info("info") logger.warning("warn") logger.error("error") logger.critical("critical")
from delogger import Delogger from delogger.decorators.debug_log import DebugLog from delogger.decorators.line_profile import LineProfileStats from delogger.modes.file import CountRotatingFileMode if __name__ == "__main__": delogger = Delogger() delogger.load_modes( CountRotatingFileMode(filepath="log/%Y/%Y-%m-%d.log", backup_count=0)) delogger.load_decorators(DebugLog(), LineProfileStats()) logger = delogger.get_logger() @logger.add_line_profile def test(): logger.debug("debug") logger.info("info") logger.warning("warn") logger.error("error") logger.critical("critical") for _ in range(2): test() logger.print_stats()