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_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_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()