Exemplo n.º 1
0
def test_spawn(capsys):
    """We expect spawned copies to inherit the log level of their parents."""

    logger1 = Loggable("Parent")
    logger1.set_level("INFO")
    logger2 = logger1.spawn("new name")

    # logger 1 output
    logger1.info("msg")
    log, _ = capsys.readouterr()
    assert "msg" in log

    # logger 2 output
    logger2.info("msg")
    log, _ = capsys.readouterr()
    assert "msg" in log

    logger1.set_level("ERROR")

    # logger 1 no output
    logger1.info("msg")
    log, _ = capsys.readouterr()
    assert not log

    # logger 2 no output
    logger2.info("msg")
    log, _ = capsys.readouterr()
    assert not log
Exemplo n.º 2
0
def test_copy(capsys):
    """We expect copies to initially inherit the log level of their parents."""

    logger1 = Loggable("Parent")
    logger1.set_level("INFO")
    logger2 = logger1.copy("newname")
    assert logger2.name == "newname"
    # logger 1 output
    logger1.info("msg")
    log, _ = capsys.readouterr()
    assert "msg" in log

    # logger 2 output
    logger2.info("msg")
    log, _ = capsys.readouterr()
    assert "msg" in log

    logger1.set_level("ERROR")

    # logger 1 output
    logger1.info("msg")
    log, _ = capsys.readouterr()
    assert not log

    # logger 2 output
    logger2.info("msg")
    log, _ = capsys.readouterr()
    assert "msg" in log
Exemplo n.º 3
0
    def test_timeit(self):
        log = Loggable("loggable_test")
        log.set_level("INFO")

        with log.timeit(logging.INFO, "TimeItTest"):
            log.info("ok")
Exemplo n.º 4
0
class Foo:
    def __init__(self):
        self.log = Loggable(self)

    def bar(self):
        self.log.info("bar")
Exemplo n.º 5
0
 def test_leveled_progress_bar(self, level):
     log = Loggable("Test")
     for x in log.tqdm(range(10), level, desc="this is a description"):
         log.info(x)
     log.info("This is more information")
Exemplo n.º 6
0
 def test_basic_progress_bar(self):
     log = Loggable("test")
     for x in tqdm(range(10)):
         log.info(x)
         time.sleep(0.01)
     log.info("This is more information")