コード例 #1
0
    def test_basic_log(self, capsys):
        logger = Loggable("loggable_test")
        logger.set_level("INFO")

        logger.timeit("INFO").info("log2")
        log, _ = capsys.readouterr()
        assert "INFO" in log
コード例 #2
0
    def test_prefix(self, capsys):
        log = Loggable("loggable_test")
        log.set_level("INFO")

        timeit = log.timeit(logging.INFO, "prefix")
        timeit.enter()
        timeit.info("Some information")
        timeit.exit()
        log, _ = capsys.readouterr()
        print(log)
        assert "prefix" in log
コード例 #3
0
 def test_spawn(self, capsys):
     log = Loggable("loggable_test")
     log.set_level("INFO")
     log2 = log.timeit(logging.INFO)
     log2.enter()
     log2.info("log2")
     log2.exit()
     msg, _ = capsys.readouterr()
     assert "started" in msg.lower()
     assert "log2" in msg
     assert "finished" in msg.lower()
コード例 #4
0
    def test_does_not_log(self, capsys):
        log = Loggable("loggable_test")
        log.set_level("ERROR")

        timeit = log.timeit(logging.INFO)
        timeit.enter()
        timeit.info("ok")
        time.sleep(0.1)
        timeit.exit()
        log, _ = capsys.readouterr()
        print(log)
        assert not log
コード例 #5
0
    def test_timeit(self, capsys):
        log = Loggable("loggable_test")
        log.set_level("INFO")

        timeit = log.timeit(logging.INFO)
        timeit.enter()
        timeit.info("ok")
        time.sleep(0.1)
        timeit.exit()
        log, _ = capsys.readouterr()
        print(log)
        assert "started" in log.lower()
        assert "ok" in log
        assert "finished" in log.lower()
コード例 #6
0
 def test_exception_is_raised_for_timeit(self):
     logger = Loggable("test loggable")
     with pytest.raises(ValueError) as e:
         with logger.timeit("ERROR"):
             raise ValueError
コード例 #7
0
    def test_timeit(self):
        log = Loggable("loggable_test")
        log.set_level("INFO")

        with log.timeit(logging.INFO, "TimeItTest"):
            log.info("ok")