예제 #1
0
def test_indent(caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # And the nesting level is not changed
    assert logger.nesting == 0
    # When the report method is called within an indentation context,
    with logger.indent():
        logger.report('make', '/some/report')
    # Then the spacing should be increased.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * 2

    # When report is called within a multi level indentation context,
    count = 5
    with logger.indent(count):
        logger.report('make', '/some/report')
    # Then the spacing should be increased accordingly.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * (count + 1)

    # When any other method is called with indentation,
    count = 3
    with logger.indent(count):
        logger.info('something')
    # Then the spacing should be added in the beginning
    assert (ReportFormatter.SPACING * count + 'something') in last_log(caplog)
예제 #2
0
def test_indent(caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # And the nesting level is not changed
    assert logger.nesting == 0
    # When the report method is called within an indentation context,
    with logger.indent():
        logger.report('make', '/some/report')
    # Then the spacing should be increased.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * 2

    # When report is called within a multi level indentation context,
    count = 5
    with logger.indent(count):
        logger.report('make', '/some/report')
    # Then the spacing should be increased accordingly.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * (count + 1)

    # When any other method is called with indentation,
    count = 3
    with logger.indent(count):
        logger.info('something')
    # Then the spacing should be added in the beginning
    assert (ReportFormatter.SPACING * count + 'something') in last_log(caplog)
예제 #3
0
def test_configure_logger(monkeypatch, caplog, reset_logger):
    # Given an environment that supports color,
    monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True)
    # when configure_logger in called,
    opts = dict(log_level=logging.INFO)
    configure_logger(opts)
    # then the formatter should be changed to use colors,
    logger.report('some', 'activity')
    out = caplog.text
    assert ansi_regex('some').search(out)
예제 #4
0
def test_configure_logger(monkeypatch, caplog, reset_logger):
    # Given an environment that supports color,
    monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True)
    # when configure_logger in called,
    opts = dict(log_level=logging.INFO)
    configure_logger(opts)
    # then the formatter should be changed to use colors,
    logger.report('some', 'activity')
    out = caplog.text
    assert ansi_regex('some').search(out)
예제 #5
0
def test_configure_logger(monkeypatch, caplog):
    # Given an environment that supports color,
    monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True)
    # when configure_logger in called,
    opts = dict(log_level=logging.INFO)
    configure_logger(opts)
    # then the formatter should be changed to use colors,
    name = uniqstr()
    logger.report('some', name)
    out = caplog.messages[-1]
    assert re.search(ansi_pattern('some') + '.+' + name, out)
예제 #6
0
def test_configure_logger(monkeypatch, caplog):
    # Given an environment that supports color,
    monkeypatch.setattr('pyscaffold.termui.supports_color', lambda *_: True)
    # when configure_logger in called,
    opts = dict(log_level=logging.INFO)
    configure_logger(opts)
    # then the formatter should be changed to use colors,
    name = uniqstr()
    logger.report('some', name)
    out = caplog.text
    assert re.search(ansi_pattern('some') + '.+' + name, out)
예제 #7
0
def test_report(caplog, tmpfolder):
    # Given the logger level is properly configured
    caplog.set_level(logging.INFO)
    # When the report method is called,
    name = uniqstr()
    logger.report('make', str(tmpfolder.join(name)))
    # Then the message should be formatted accordingly.
    logs = caplog.text
    match = re.search('make.+' + name, logs)
    assert match
    # And relative paths should be used
    assert lp('/tmp') not in match.group(0)
예제 #8
0
def test_report(caplog, tmpfolder):
    # Given the logger level is properly configured
    caplog.set_level(logging.INFO)
    # When the report method is called,
    name = uniqstr()
    logger.report('make', str(tmpfolder.join(name)))
    # Then the message should be formatted accordingly.
    logs = caplog.text
    match = re.search('make.+' + name, logs)
    assert match
    # And relative paths should be used
    assert '/tmp' not in match.group(0)
예제 #9
0
def test_colored_report(tmpfolder, caplog, reset_logger):
    # Given the logger is properly set,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    logger.handler.setFormatter(ColoredReportFormatter())
    # When the report method is called,
    logger.report('make', str(tmpfolder) + '/some/report')
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.text
    assert ansi_regex('make').search(out)
    # And relative paths should be used
    assert '/tmp' not in out
    assert 'some/report' in out
예제 #10
0
def test_colored_report(tmpfolder, caplog, reset_logger):
    # Given the logger is properly set,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    logger.handler.setFormatter(ColoredReportFormatter())
    # When the report method is called,
    logger.report('make', str(tmpfolder) + '/some/report')
    # Then the message should contain activity surrounded by ansi codes,
    out = caplog.text
    assert ansi_regex('make').search(out)
    # And relative paths should be used
    assert '/tmp' not in out
    assert 'some/report' in out
예제 #11
0
def test_report(tmpfolder, caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # When the report method is called,
    logger.report('make', str(tmpfolder) + '/some/report')
    # Then the message should be formatted accordingly.
    match = match_last_report(caplog)
    assert match['activity'] == 'make'
    assert match['content'] == 'some/report'
    # And relative paths should be used
    out = caplog.text
    assert '/tmp' not in out
    assert 'some/report' in out
예제 #12
0
def test_report(tmpfolder, caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # When the report method is called,
    logger.report('make', str(tmpfolder) + '/some/report')
    # Then the message should be formatted accordingly.
    match = match_last_report(caplog)
    assert match['activity'] == 'make'
    assert match['content'] == 'some/report'
    # And relative paths should be used
    out = caplog.text
    assert '/tmp' not in out
    assert 'some/report' in out
예제 #13
0
def test_copy(caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # And the nesting level is not changed
    assert logger.nesting == 0
    # And a copy of the logger is made withing a context,
    count = 3
    with logger.indent(count):
        logger2 = logger.copy()
    # When the original logger indentation level is changed,
    with logger.indent(7):
        logger.report('make', '/some/report')
        # And the report method is called in the clone logger
        logger2.report('call', '/other/logger')

    # Then the spacing should not be increased.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * (count + 1)
예제 #14
0
def test_copy(caplog, reset_logger):
    # Given the logger level is set to INFO,
    logging.getLogger(DEFAULT_LOGGER).setLevel(logging.INFO)
    # And the nesting level is not changed
    assert logger.nesting == 0
    # And a copy of the logger is made withing a context,
    count = 3
    with logger.indent(count):
        logger2 = logger.copy()
    # When the original logger indentation level is changed,
    with logger.indent(7):
        logger.report('make', '/some/report')
        # And the report method is called in the clone logger
        logger2.report('call', '/other/logger')

    # Then the spacing should not be increased.
    match = match_last_report(caplog)
    assert match['spacing'] == ReportFormatter.SPACING * (count + 1)