Exemplo n.º 1
0
def test_checker_summary_print_status(patches, errors, warnings):
    checker = DummyChecker()
    summary = CheckerSummary(checker)
    summary.checker = MagicMock()
    summary.checker.errors = errors
    summary.checker.warnings = warnings

    assert not summary.print_status()

    if errors:
        assert (list(summary.checker.log.error.call_args) == [
            (f"{summary.checker.status}", ), {}
        ])
        assert not summary.checker.log.warning.called
        assert not summary.checker.log.info.called
        return

    if warnings:
        assert (list(summary.checker.log.warning.call_args) == [
            (f"{summary.checker.status}", ), {}
        ])
        assert not summary.checker.log.error.called
        assert not summary.checker.log.info.called
        return

    assert (list(summary.checker.log.info.call_args) == [
        (f"{summary.checker.status}", ), {}
    ])
    assert not summary.checker.log.error.called
    assert not summary.checker.log.warning.called
Exemplo n.º 2
0
def test_checker_summary_print_status(patches):
    checker = DummyChecker()
    summary = CheckerSummary(checker)
    patched = patches("CheckerSummary._section", prefix="tools.base.checker")

    summary.checker = MagicMock()
    with patched as (m_section, ):
        m_section.return_value = ["A", "B", "C"]
        summary.print_status()
    assert (list(m_section.call_args) == [
        (f"[SUMMARY:{summary.checker.name}] {summary.checker.status}", ), {}
    ])
    assert (list(summary.checker.log.warning.call_args) == [('A\nB\nC', ), {}])
Exemplo n.º 3
0
def test_checker_summary_print_failed(patches, problem_type, max_display, problems):
    checker = DummyChecker()
    summary = CheckerSummary(checker)
    patched = patches(
        "CheckerSummary._section",
        (f"CheckerSummary.max_{problem_type}", dict(new_callable=PropertyMock)),
        prefix="tools.base.checker")

    with patched as (m_section, m_max):
        summary.checker = MagicMock()
        setattr(summary.checker, f"{problem_type}", problems)
        m_max.return_value = max_display
        m_section.return_value = ["A", "B", "C"]
        summary.print_failed(problem_type)

    if not problems:
        assert not summary.checker.log.error.called
        assert not m_section.called
        return

    output = (
        summary.checker.log.warning if problem_type == "warnings" else summary.checker.log.error)

    assert (
        list(output.call_args)
        == [("".join(['A\nB\nC\n'] * len(problems)),), {}])

    if max_display == 0:
        expected = [
            [(f"{summary.checker.name} {prob}", []), {}]
            for prob in problems]
    else:
        def _problems(prob):
            return (
                problems[prob][:max_display]
                if max_display > 0
                else problems[prob])
        def _extra(prob):
            return (
                f": (showing first {max_display} of {len(problems)})"
                if len(problems[prob]) > max_display and max_display >= 0
                else (":"
                      if max_display != 0
                      else ""))
        expected = [
            [(f"{summary.checker.name} {prob}{_extra(prob)}", _problems(prob)), {}]
            for prob in problems]
    assert (
        list(list(c) for c in m_section.call_args_list)
        == expected)