예제 #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_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
예제 #3
0
    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
예제 #4
0
    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())
예제 #5
0
    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())
예제 #6
0
    def test_not_can_run(self):
        delogger = Delogger("can_not_run")
        delogger.load_decorator(_CanNotRun())
        logger = delogger.get_logger()

        @logger.can_not_run
        def test_func():
            return 1

        ret = test_func()

        assert ret == 1
예제 #7
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
예제 #8
0
    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()
예제 #9
0
    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()
예제 #10
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
예제 #11
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
예제 #12
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()
예제 #13
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")