Exemple #1
0
def test_copy(caplog):
    # Given the logger level is set to INFO,
    caplog.set_level(logging.INFO)
    lg = logger.copy()  # Create a local copy to avoid shared state
    # And the nesting level is known
    nesting = lg.nesting
    # And a copy of the logger is made withing a context,
    count = 3
    with lg.indent(count):
        logger2 = lg.copy()
    # When the original logger indentation level is changed,
    name = uniqstr()
    with lg.indent(7):
        lg.report('make', '/some/report')
        # And the report method is called in the copy logger
        logger2.report('call', name)
        # Then the logging level should not be changed
        assert logger2.nesting == nesting + count

    # And the spacing should not be increased.
    assert any(
        match_report(r,
                     activity='call',
                     content=name,
                     spacing=ReportFormatter.SPACING * (nesting + count + 1))
        for r in caplog.records)
Exemple #2
0
def test_copy(caplog):
    # Given the logger level is set to INFO,
    caplog.set_level(logging.INFO)
    lg = logger.copy()  # Create a local copy to avoid shared state
    # And the nesting level is known
    nesting = lg.nesting
    # And a copy of the logger is made withing a context,
    count = 3
    with lg.indent(count):
        logger2 = lg.copy()
    # When the original logger indentation level is changed,
    name = uniqstr()
    with lg.indent(7):
        lg.report('make', '/some/report')
        # And the report method is called in the copy logger
        logger2.report('call', name)
        # Then the logging level should not be changed
        assert logger2.nesting == nesting + count

    # And the spacing should not be increased.
    assert any(
        match_report(r, activity='call', content=name,
                     spacing=ReportFormatter.SPACING * (nesting + count + 1))
        for r in caplog.records
    )
Exemple #3
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)
Exemple #4
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)
Exemple #5
0
def test_indent(caplog):
    # Given the logger level is set to INFO,
    caplog.set_level(logging.INFO)
    lg = logger.copy()  # Create a local copy to avoid shared state
    # And the nesting level is known
    nesting = lg.nesting
    # When the report method is called within an indentation context,
    name = uniqstr()
    with lg.indent():
        lg.report("make", name)
    # Then the spacing should be increased.
    assert any(
        match_report(
            r,
            activity="make",
            content=name,
            spacing=ReportFormatter.SPACING * (nesting + 2),
        ) for r in caplog.records)

    # When report is called within a multi level indentation context,
    count = 5
    name = uniqstr()
    with lg.indent(count):
        lg.report("make", name)
    # Then the spacing should be increased accordingly.
    assert any(
        match_report(
            r,
            activity="make",
            content=name,
            spacing=ReportFormatter.SPACING * (nesting + count + 1),
        ) for r in caplog.records)

    # When any other method is called with indentation,
    count = 3
    name = uniqstr()
    with lg.indent(count):
        lg.info(name)
    # Then the spacing should be added in the beginning
    logs = caplog.text
    assert (ReportFormatter.SPACING * (nesting + count) + name) in logs
Exemple #6
0
def test_indent(caplog):
    # Given the logger level is set to INFO,
    caplog.set_level(logging.INFO)
    lg = logger.copy()  # Create a local copy to avoid shared state
    # And the nesting level is known
    nesting = lg.nesting
    # When the report method is called within an indentation context,
    name = uniqstr()
    with lg.indent():
        lg.report('make', name)
    # Then the spacing should be increased.
    assert any(
        match_report(r, activity='make', content=name,
                     spacing=ReportFormatter.SPACING * (nesting + 2))
        for r in caplog.records
    )

    # When report is called within a multi level indentation context,
    count = 5
    name = uniqstr()
    with lg.indent(count):
        lg.report('make', name)
    # Then the spacing should be increased accordingly.
    assert any(
        match_report(r, activity='make', content=name,
                     spacing=ReportFormatter.SPACING * (nesting + count + 1))
        for r in caplog.records
    )

    # When any other method is called with indentation,
    count = 3
    name = uniqstr()
    with lg.indent(count):
        lg.info(name)
    # Then the spacing should be added in the beginning
    logs = caplog.text
    assert (ReportFormatter.SPACING * (nesting + count) + name) in logs