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
def test_checker_summary_section(section): checker = DummyChecker() summary = CheckerSummary(checker) message, lines = section expected = ["Summary", "-" * 80, f"{message}"] if lines: expected += lines assert summary._section(message, lines) == expected
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', ), {}])
def test_checker_summary_print_summary(patches): checker = DummyChecker() summary = CheckerSummary(checker) patched = patches("CheckerSummary.print_failed", "CheckerSummary.print_status", prefix="tools.base.checker") with patched as (m_failed, m_status): summary.print_summary() assert (list(list(c) for c in m_failed.call_args_list) == [[('warnings', ), {}], [('errors', ), {}]]) assert m_status.called
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)
def test_checker_summary_max_warnings(max_warnings): checker = DummyChecker() summary = CheckerSummary(checker) checker.args.summary_warnings = max_warnings assert summary.max_warnings == max_warnings
def test_checker_summary_max_errors(max_errors): checker = DummyChecker() summary = CheckerSummary(checker) checker.args.summary_errors = max_errors assert summary.max_errors == max_errors
def test_checker_summary_constructor(): checker = DummyChecker() summary = CheckerSummary(checker) assert summary.checker == checker