Ejemplo n.º 1
0
def exception_processing(n_survivors: int,
                         trial_results: List[MutantTrialResult]) -> None:
    """Raise a custom mutation exception if ``n_survivors`` count is met.

    Args:
        n_survivors: tolerance number for survivors
        trial_results: results from the trials

    Returns:
        None

    Raises:
        SurvivingMutantException: if the number of survivors is exceeded.
    """
    survived = report.get_reported_results(trial_results, "SURVIVED")
    if len(survived.mutants) >= n_survivors:
        message = run.colorize_output(
            f"Survivor tolerance breached: {len(survived.mutants)} / {n_survivors}",
            "red")
        raise SurvivingMutantException(message)

    LOGGER.info(
        "%s",
        run.colorize_output(
            f"Survivor tolerance OK: {len(survived.mutants)} / {n_survivors}",
            "green"),
    )
Ejemplo n.º 2
0
def test_colorize_output_invariant_valid(color, o):
    """Property:
        1. Valid colorized output start and end with assumed terminal markers.
    """
    result = run.colorize_output(o, color)
    assert result.startswith("\x1b[")
    assert result.endswith("\x1b[0m")
Ejemplo n.º 3
0
def test_colorize_output_invariant_return(o, c):
    """Property:
        1. Colorized output always returns the unmodified string for invalid entries.
    """
    assume(c not in VALID_COLORS)

    result = run.colorize_output(o, c)
    assert result == o
Ejemplo n.º 4
0
def analyze_mutant_trials(
        trial_results: List[MutantTrialResult]) -> Tuple[str, DisplayResults]:
    """Create the analysis text report string for the trials.

    Additionally, return a DisplayResults NamedTuple that includes terminal coloring for the
    output on the terminal.

    It will look like:

    .. code-block::

        Overall mutation trial summary:
        ===============================
        DETECTED: x
        TIMEOUT: w
        SURVIVED: y
        ...

        Breakdown by section:
        =====================

        Section title
        -------------
        source_file.py: (l: 1, c: 10) - mutation from op.Original to op.Mutated
        source_file.py: (l: 3, c: 10) - mutation from op.Original to op.Mutated

    Args:
        trial_results: list of ``MutantTrial`` results

    Returns:
        Tuple: (text report, ``DisplayResults``)
    """
    status = get_status_summary(trial_results)

    detected = get_reported_results(trial_results, "DETECTED")
    timeouts = get_reported_results(trial_results, "TIMEOUT")
    survived = get_reported_results(trial_results, "SURVIVED")
    errors = get_reported_results(trial_results, "ERROR")
    unknowns = get_reported_results(trial_results, "UNKNOWN")

    report_sections = []

    # build the summary section
    summary_header = "Overall mutation trial summary"
    report_sections.append("\n".join(
        [summary_header, "=" * len(summary_header)]))
    for s, n in status.items():
        report_sections.append(f" - {s}: {n}")

    # prepare display of summary results, no color applied
    display_summary = "\n".join(report_sections)
    display_survived, display_timedout, display_detected = "", "", ""

    # build the breakout sections for each type
    section_header = "Mutations by result status"
    report_sections.append("\n".join(
        ["\n", section_header, "=" * len(section_header)]))
    for rpt_results in [survived, timeouts, detected, errors, unknowns]:
        if rpt_results.mutants:
            section = build_report_section(rpt_results.status,
                                           rpt_results.mutants)
            report_sections.append(section)

            if rpt_results.status == "SURVIVED":
                display_survived = run.colorize_output(section, "red")

            if rpt_results.status == "TIMEOUT":
                display_timedout = run.colorize_output(section, "yellow")

            if rpt_results.status == "DETECTED":
                display_detected = run.colorize_output(section, "green")

    return (
        "\n".join(report_sections),
        DisplayResults(
            summary=display_summary,
            detected=display_detected,
            timedout=display_timedout,
            survived=display_survived,
        ),
    )