def display_statistical_summary(
    counts: Dict[str, int],
    event: events.Finished,
    warnings: FrozenSet[str],
    color: str = "cyan",
) -> None:
    click.echo()
    default.display_section_name("STATISTICS")
    click.echo()
    error_count, warning_count = (
        counts["errors"],
        counts["warnings"],
    )
    click.secho(f"Total warnings: {warning_count}", fg=color)
    click.secho(f"Total errors: {error_count}", fg=color)
    for severity, check_stats in get_results_by_severity(event, warnings).items():
        if check_stats:
            click.echo()
            click.secho(severity, fg=color, bold=True, underline=True)
            # prints the check name and counts in descending order by count
            for check_name, count in sorted(
                check_stats.items(), key=lambda x: x[1], reverse=True
            ):
                click.secho(f"{check_name} : {count}", fg=color)
    click.echo()
def display_summary(
    event: events.Finished, warnings: FrozenSet[str], statistics: bool = False
) -> None:
    counts = get_summary_counts(event, warnings)
    message, color, status_code = get_summary_output(counts, event, warnings)
    if statistics:
        display_statistical_summary(counts, event, warnings, color)
    default.display_section_name(message, fg=color)
    raise click.exceptions.Exit(status_code)
Esempio n. 3
0
def test_display_section_name(capsys, title, separator, printed, expected):
    # When section name is displayed
    default.display_section_name(title, separator=separator)
    out = capsys.readouterr().out.strip()
    terminal_width = default.get_terminal_width()
    # It should fit into the terminal width
    assert len(click.unstyle(out)) == terminal_width
    # And the section name should be bold
    assert strip_style_win32(click.style(click.unstyle(out), bold=True)) == out
    assert expected in out
def display_exceptions(context: ExecutionContext, event: events.Finished) -> None:
    """Display all exceptions in the test run."""
    if not event.has_errors:
        return

    default.display_section_name("EXCEPTIONS")
    for result in context.results:
        if result.has_errors:
            display_single_exception(context, result)
    if not context.show_errors_tracebacks:
        click.secho(
            "Add this option to your command line parameters to see full tracebacks: --show-exception-tracebacks",
            fg="magenta",
        )
def display_warnings(
    context: ExecutionContext, event: events.Finished, warnings: FrozenSet[str]
) -> None:
    """Display all warnings in the test run."""
    if not event.has_failures:
        return
    warning_results = [
        result for result in context.results if contains_warning(result, warnings)
    ]
    if warning_results:
        default.display_section_name("WARNINGS")
        for result in warning_results:
            display_single_test(
                get_unique_warnings(result.checks, warnings), result, "yellow"
            )
def display_errors(
    context: ExecutionContext, event: events.Finished, warnings: FrozenSet[str]
) -> None:
    """Display all errors in the test run."""
    if not event.has_failures and not event.has_errors:
        return
    errors = [
        result
        for result in context.results
        if result.has_failures and not warn_or_success(result, warnings)
    ]
    if errors:
        default.display_section_name("ERRORS")
        for result in errors:
            display_single_test(get_unique_errors(result.checks, warnings), result, "red")
def display_totals(
    context: ExecutionContext, event: events.Finished, warnings: FrozenSet[str]
) -> None:
    """Format and print statistic collected by :obj:`models.TestResult`."""
    default.display_section_name("SUMMARY")
    click.echo()
    total = event.total
    if event.is_empty or not total:
        click.secho("No checks were performed.", bold=True)

    if total:
        display_checks_totals(total, warnings)

    if context.cassette_file_name or context.junit_xml_file:
        click.echo()

    if context.cassette_file_name:
        category = click.style("Network log", bold=True)
        click.secho(f"{category}: {context.cassette_file_name}")

    if context.junit_xml_file:
        category = click.style("JUnit XML file", bold=True)
        click.secho(f"{category}: {context.junit_xml_file}")