def diff( cobertura_file1, cobertura_file2, color, format, output, source1, source2, source_prefix1, source_prefix2, source, ): """compare coverage of two Cobertura reports""" # Assume that the source is located in the same directory as the provided # coverage files if no source directories are provided. if not source1: source1 = get_dir_from_file_path(cobertura_file1) if not source2: source2 = get_dir_from_file_path(cobertura_file2) filesystem1 = filesystem_factory(source1, source_prefix=source_prefix1) cobertura1 = Cobertura(cobertura_file1, filesystem=filesystem1) filesystem2 = filesystem_factory(source2, source_prefix=source_prefix2) cobertura2 = Cobertura(cobertura_file2, filesystem=filesystem2) Reporter = delta_reporters[format] reporter_args = [cobertura1, cobertura2] reporter_kwargs = {"show_source": source} isatty = True if output is None else output.isatty() if format == "text": color = isatty if color is None else color is True reporter_kwargs["color"] = color reporter = Reporter(*reporter_args, **reporter_kwargs) report = reporter.generate() if not isinstance(report, bytes): report = report.encode("utf-8") click.echo(report, file=output, nl=isatty, color=color) exit_code = get_exit_code(reporter.differ, source) raise SystemExit(exit_code)
def print_line_text_report(self, cobertura_xml: str): cobertura_filesystem = filesystem_factory( source=self._configuration.project_path) cobertura = CheckedCobertura(cobertura_xml, filesystem=cobertura_filesystem) text_reporter = CheckedTextLineReporter(cobertura) text_report = text_reporter.generate() print(text_report)
def diff( cobertura_file1, cobertura_file2, color, format, output, source1, source2, source_prefix1, source_prefix2, source, ): """compare coverage of two Cobertura reports""" fs1 = filesystem_factory(report=cobertura_file1, source=source1, source_prefix=source_prefix1) fs2 = filesystem_factory(report=cobertura_file2, source=source2, source_prefix=source_prefix2) cobertura1 = Cobertura(cobertura_file1, filesystem=fs1) cobertura2 = Cobertura(cobertura_file2, filesystem=fs2) Reporter = delta_reporters[format] reporter_args = [cobertura1, cobertura2] reporter_kwargs = {"show_source": source} isatty = True if output is None else output.isatty() if format == "text": color = isatty if color is None else color is True reporter_kwargs["color"] = color reporter = Reporter(*reporter_args, **reporter_kwargs) report = reporter.generate() if not isinstance(report, bytes): report = report.encode("utf-8") click.echo(report, file=output, nl=isatty, color=color) exit_code = get_exit_code(reporter.differ, source) raise SystemExit(exit_code)
def show(cobertura_file, format, output, source, source_prefix): """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)
def generate_line_text_report(self, cobertura_xml: str): cobertura_filesystem = filesystem_factory( source=self._configuration.project_path) cobertura = CheckedCobertura(cobertura_xml, filesystem=cobertura_filesystem) text_reporter = CheckedTextLineReporter(cobertura) text_report = text_reporter.generate() output_path = self._make_output_directory() output_file = os.path.join(output_path, "line_coverage.txt") with open(output_file, "w") as text_file: text_file.write(text_report)
def __init__(self, report, filesystem=None): """ Initialize a Cobertura report given a coverage report `report`. It can be either a file object or the path to an XML file that is in the Cobertura format. The optional argument `filesystem` describes how to retrieve the source files referenced in the report. Please check the pycobertura.filesystem module in order to discover more about filesystems. """ self.xml = ET.parse(report).getroot() self.report = report if isinstance(report, basestring) else None if filesystem: self.filesystem = filesystem else: self.filesystem = filesystem_factory(self.report)
def test_filesystem_factory(): from pycobertura.filesystem import filesystem_factory, GitFileSystem fs = filesystem_factory(source=".", ref=FIRST_PYCOBERTURA_COMMIT_SHA) assert isinstance(fs, GitFileSystem)
def make_cobertura(xml=SOURCE_FILE, **kwargs): from pycobertura import Cobertura from pycobertura.filesystem import filesystem_factory source_filesystem = filesystem_factory(xml, **kwargs) cobertura = Cobertura(xml, filesystem=source_filesystem) return cobertura
def make_cobertura(xml='tests/cobertura.xml', source=None, **kwargs): if not source: source = get_dir_from_file_path(xml) source_filesystem = filesystem_factory(source, **kwargs) cobertura = Cobertura(xml, filesystem=source_filesystem) return cobertura