How to use the pycobertura.reporters.TextReporterDelta function in pycobertura

To help you get started, we’ve selected a few pycobertura examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aconrad / pycobertura / tests / test_reporters.py View on Github external
def test_text_report_delta__colorize_True__with_missing_range():
    from pycobertura.reporters import TextReporterDelta

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source2/coverage.xml')

    report_delta = TextReporterDelta(cobertura1, cobertura2, color=True)

    assert report_delta.generate() == """\
Filename         Stmts      Miss  Cover    Missing
github aconrad / pycobertura / tests / test_reporters.py View on Github external
def test_text_report_delta__colorize_False():
    from pycobertura.reporters import TextReporterDelta

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source2/coverage.xml')

    report_delta = TextReporterDelta(cobertura1, cobertura2, color=False)

    assert report_delta.generate() == """\
Filename         Stmts      Miss  Cover    Missing
github aconrad / pycobertura / tests / test_reporters.py View on Github external
def test_text_report_delta__colorize_True():
    from pycobertura.reporters import TextReporterDelta

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source2/coverage.xml')

    report_delta = TextReporterDelta(cobertura1, cobertura2, color=True)

    assert report_delta.generate() == """\
Filename         Stmts      Miss  Cover    Missing
github aconrad / pycobertura / tests / test_reporters.py View on Github external
def test_text_report_delta__no_diff():
    from pycobertura.reporters import TextReporterDelta

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source1/coverage.xml')

    report_delta = TextReporterDelta(cobertura1, cobertura2)

    assert report_delta.generate() == """\
Filename    Stmts    Miss    Cover    Missing
github aconrad / pycobertura / tests / test_reporters.py View on Github external
def test_text_report_delta__no_source():
    from pycobertura.reporters import TextReporterDelta

    cobertura1 = make_cobertura('tests/dummy.source1/coverage.xml')
    cobertura2 = make_cobertura('tests/dummy.source2/coverage.xml')

    report_delta = TextReporterDelta(cobertura1, cobertura2, show_source=False)
    output = report_delta.generate()
    assert output == """\
Filename         Stmts      Miss  Cover
github aconrad / pycobertura / pycobertura / cli.py View on Github external
"""show coverage summary of a Cobertura report"""
    fs = filesystem_factory(cobertura_file, source=source)
    cobertura = Cobertura(cobertura_file, filesystem=fs)
    Reporter = reporters[format]
    reporter = Reporter(cobertura)
    report = reporter.generate()

    if not isinstance(report, bytes):
        report = report.encode("utf-8")

    isatty = True if output is None else output.isatty()
    click.echo(report, file=output, nl=isatty)


delta_reporters = {
    "text": TextReporterDelta,
    "html": HtmlReporterDelta,
}


@pycobertura.command(
    help="""\
The diff command compares and shows the changes between two Cobertura reports.

NOTE: Reporting missing lines or showing the source code with the diff command
can only be accurately computed if the versions of the source code used to
generate each of the coverage reports is accessible. By default, the source
will read from the Cobertura report and resolved relatively from the report's
location. If the source is not accessible from the report's location, the
options `--source1` and `--source2` are necessary to point to the source code
directories (or zip archives). If the source is not available at all, pass
`--no-source` but missing lines and source code will not be reported.
github aconrad / pycobertura / pycobertura / reporters.py View on Github external
def __init__(self, *args, **kwargs):
        """
        Takes the same arguments as `DeltaReporter` but also takes the keyword
        argument `color` which can be set to True or False depending if the
        generated report should be colored or not (default `color=False`).
        """
        self.color = kwargs.pop("color", False)
        super(TextReporterDelta, self).__init__(*args, **kwargs)
github aconrad / pycobertura / pycobertura / reporters.py View on Github external
formatted_lines = []
        for row in lines:
            formatted_row = self.format_row(row)
            formatted_lines.append(formatted_row)

        headers = ["Filename", "Stmts", "Miss", "Cover"]

        if self.show_source is True:
            headers.append("Missing")

        report = tabulate(formatted_lines, headers=headers)

        return report


class HtmlReporterDelta(TextReporterDelta):
    def get_source_hunks(self, filename):
        hunks = self.differ.file_source_hunks(filename)
        return hunks

    def format_row(self, row):
        total_statements = "%+d" % row.total_statements if row.total_statements else "-"
        total_misses = "%+d" % row.total_misses if row.total_misses else "-"
        line_rate = "%+.2f%%" % (row.line_rate * 100) if row.line_rate else "-"

        if self.show_source is True:
            missed_lines = [
                "%s%d" % (["-", "+"][is_new], lno) for lno, is_new in row.missed_lines
            ]

        row_values = [
            row.filename,