예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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()
예제 #6
0
파일: debug.py 프로젝트: deresmos/delogger
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")
예제 #7
0
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()