Exemplo n.º 1
0
def test_colored_report(tmpfolder, caplog, uniq_raw_logger):
    # Given the logger is properly set,
    uniq_raw_logger.setLevel(logging.INFO)
    uniq_logger = ReportLogger(uniq_raw_logger,
                               formatter=ColoredReportFormatter())
    # When the report method is called,
    name = uniqstr()
    uniq_logger.report('make', str(tmpfolder.join(name)))
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.text
    assert re.search(ansi_pattern('make') + '.+' + name, out)
    # And relative paths should be used
    assert '/tmp' not in out
Exemplo n.º 2
0
def test_colored_report(tmpfolder, caplog, uniq_raw_logger):
    # Given the logger is properly set,
    uniq_raw_logger.setLevel(logging.INFO)
    uniq_logger = ReportLogger(uniq_raw_logger,
                               formatter=ColoredReportFormatter())
    # When the report method is called,
    name = uniqstr()
    uniq_logger.report('make', str(tmpfolder.join(name)))
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.text
    assert re.search(ansi_pattern('make') + '.+' + name, out)
    # And relative paths should be used
    assert '/tmp' not in out
Exemplo n.º 3
0
def test_colored_report(tmpfolder, caplog, uniq_raw_logger):
    # Given the logger is properly set,
    uniq_raw_logger.setLevel(logging.INFO)
    formatter = ColoredReportFormatter()
    uniq_logger = ReportLogger(uniq_raw_logger,
                               formatter=formatter,
                               propagate=True)
    # When the report method is called,
    name = uniqstr()
    uniq_logger.report("make", str(tmpfolder.join(name)))
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.messages[-1]
    assert re.search(ansi_pattern("make") + ".+" + name, out)
    # And relative paths should be used
    assert lp("/tmp") not in out
Exemplo n.º 4
0
def test_reconfigure(monkeypatch, caplog, uniq_raw_logger):
    # Given an environment that supports color, and a restrictive logger
    caplog.set_level(logging.NOTSET)
    monkeypatch.setattr("pyscaffold.termui.supports_color", lambda *_: True)
    new_logger = ReportLogger(uniq_raw_logger, formatter=ReportFormatter())
    new_logger.level = logging.INFO
    # when the logger is reconfigured
    new_logger.reconfigure()
    name = uniqstr()
    # then the messages should be displayed and use colors
    new_logger.report("some1", name)
    out = caplog.messages[-1]
    assert re.search(ansi_pattern("some1") + ".+" + name, out)

    # when the logger is reconfigured with a higher level
    new_logger.reconfigure(log_level=logging.CRITICAL)
    # then the messages should not be displayed
    name = uniqstr()
    new_logger.report("some2", name)
    assert not re.search(ansi_pattern("some2") + ".+" + name, caplog.text)