示例#1
0
    def xml_report(self,
                   morfs=None,
                   outfile=None,
                   ignore_errors=None,
                   omit=None,
                   include=None):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See `coverage.report()` for other arguments.

        """
        self.config.from_args(
            ignore_errors=ignore_errors,
            omit=omit,
            include=include,
            xml_output=outfile,
        )
        file_to_close = None
        if self.config.xml_output:
            if self.config.xml_output == '-':
                outfile = sys.stdout
            else:
                outfile = open(self.config.xml_output, "w")
                file_to_close = outfile
        try:
            reporter = XmlReporter(self, self.config.ignore_errors)
            reporter.report(morfs, outfile=outfile, config=self.config)
        finally:
            if file_to_close:
                file_to_close.close()
示例#2
0
    def xml_report(self, morfs=None, outfile=None, ignore_errors=None,
                    omit=None, include=None):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See `coverage.report()` for other arguments.

        """
        self.config.from_args(
            ignore_errors=ignore_errors, omit=omit, include=include,
            xml_output=outfile,
            )
        file_to_close = None
        if self.config.xml_output:
            if self.config.xml_output == '-':
                outfile = sys.stdout
            else:
                outfile = open(self.config.xml_output, "w")
                file_to_close = outfile
        try:
            reporter = XmlReporter(self, self.config.ignore_errors)
            reporter.report(morfs, outfile=outfile, config=self.config)
        finally:
            if file_to_close:
                file_to_close.close()
示例#3
0
 def xml_report(self,
                morfs=None,
                outfile=None,
                ignore_errors=None,
                omit=None,
                include=None):
     self._harvest_data()
     self.config.from_args(ignore_errors=ignore_errors,
                           omit=omit,
                           include=include,
                           xml_output=outfile)
     file_to_close = None
     delete_file = False
     if self.config.xml_output:
         if self.config.xml_output == '-':
             outfile = sys.stdout
         else:
             outfile = open(self.config.xml_output, 'w')
             file_to_close = outfile
     try:
         reporter = XmlReporter(self, self.config)
         return reporter.report(morfs, outfile=outfile)
     except CoverageException:
         delete_file = True
         raise
     finally:
         if file_to_close:
             file_to_close.close()
             if delete_file:
                 file_be_gone(self.config.xml_output)
示例#4
0
文件: control.py 项目: uceo/uceo-2015
    def xml_report(self, morfs=None, outfile=None, ignore_errors=None, omit=None, include=None):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See `coverage.report()` for other arguments.

        Returns a float, the total percentage covered.

        """
        self._harvest_data()
        self.config.from_args(ignore_errors=ignore_errors, omit=omit, include=include, xml_output=outfile)
        file_to_close = None
        delete_file = False
        if self.config.xml_output:
            if self.config.xml_output == "-":
                outfile = sys.stdout
            else:
                outfile = open(self.config.xml_output, "w")
                file_to_close = outfile
        try:
            try:
                reporter = XmlReporter(self, self.config)
                return reporter.report(morfs, outfile=outfile)
            except CoverageException:
                delete_file = True
                raise
        finally:
            if file_to_close:
                file_to_close.close()
                if delete_file:
                    file_be_gone(self.config.xml_output)
示例#5
0
    def run(self) -> int:
        coverage = Coverage()
        coverage.start()
        exit_code = main(['-v', 'tests'])
        coverage.stop()

        # Early exit if pytest failed
        if exit_code != 0:
            return 0

        # Generate xml report in StringIO file
        coverage.get_data()
        coverage.config.from_args(
            ignore_errors=None,
            report_omit=None,
            report_include=None,
            xml_output=None,
        )
        data = StringIO()
        reporter = XmlReporter(coverage, coverage.config)
        reporter.report(None, data)
        data.seek(0)

        # Check diff cover compared to origin/master using xml
        score = generate_coverage_report(coverage_xml=[data],
                                         compare_branch='origin/master',
                                         exclude=self.exclude_paths)

        return score
示例#6
0
    def xml_report(
        self,
        morfs=None,
        outfile=None,
        ignore_errors=None,
        omit=None,
        include=None,
    ):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See :meth:`report` for other arguments.

        Returns a float, the total percentage covered.

        """
        self.get_data()
        self.config.from_args(
            ignore_errors=ignore_errors,
            omit=omit,
            include=include,
            xml_output=outfile,
        )
        file_to_close = None
        delete_file = False
        if self.config.xml_output:
            if self.config.xml_output == '-':
                outfile = sys.stdout
            else:
                # Ensure that the output directory is created; done here
                # because this report pre-opens the output file.
                # HTMLReport does this using the Report plumbing because
                # its task is more complex, being multiple files.
                output_dir = os.path.dirname(self.config.xml_output)
                if output_dir and not os.path.isdir(output_dir):
                    os.makedirs(output_dir)
                open_kwargs = {}
                if env.PY3:
                    open_kwargs['encoding'] = 'utf8'
                outfile = open(self.config.xml_output, "w", **open_kwargs)
                file_to_close = outfile
        try:
            reporter = XmlReporter(self, self.config)
            return reporter.report(morfs, outfile=outfile)
        except CoverageException:
            delete_file = True
            raise
        finally:
            if file_to_close:
                file_to_close.close()
                if delete_file:
                    file_be_gone(self.config.xml_output)
示例#7
0
    def xml_report(
        self, morfs=None, outfile=None, ignore_errors=None,
        omit=None, include=None,
    ):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See :meth:`report` for other arguments.

        Returns a float, the total percentage covered.

        """
        self.get_data()
        self.config.from_args(
            ignore_errors=ignore_errors, omit=omit, include=include,
            xml_output=outfile,
            )
        file_to_close = None
        delete_file = False
        if self.config.xml_output:
            if self.config.xml_output == '-':
                outfile = sys.stdout
            else:
                # Ensure that the output directory is created; done here
                # because this report pre-opens the output file.
                # HTMLReport does this using the Report plumbing because
                # its task is more complex, being multiple files.
                output_dir = os.path.dirname(self.config.xml_output)
                if output_dir and not os.path.isdir(output_dir):
                    os.makedirs(output_dir)
                open_kwargs = {}
                if env.PY3:
                    open_kwargs['encoding'] = 'utf8'
                outfile = open(self.config.xml_output, "w", **open_kwargs)
                file_to_close = outfile
        try:
            reporter = XmlReporter(self, self.config)
            return reporter.report(morfs, outfile=outfile)
        except CoverageException:
            delete_file = True
            raise
        finally:
            if file_to_close:
                file_to_close.close()
                if delete_file:
                    file_be_gone(self.config.xml_output)
示例#8
0
文件: control.py 项目: samucc/kuma
 def xml_report(self, morfs=None, outfile=None, ignore_errors=False,
                 omit_prefixes=None):
     """Generate an XML report of coverage results.
     
     The report is compatible with Cobertura reports.
     
     """
     if outfile:
         outfile = open(outfile, "w")
     try:
         reporter = XmlReporter(self, ignore_errors)
         reporter.report(
             morfs, omit_prefixes=omit_prefixes, outfile=outfile)
     finally:
         outfile.close()
    def xml_report(
        self,
        morfs=None,
        outfile=None,
        ignore_errors=None,
        omit=None,
        include=None,
        contexts=None,
        skip_empty=None,
    ):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See :meth:`report` for other arguments.

        Returns a float, the total percentage covered.

        """
        with override_config(
                self,
                ignore_errors=ignore_errors,
                report_omit=omit,
                report_include=include,
                xml_output=outfile,
                report_contexts=contexts,
                skip_empty=skip_empty,
        ):
            return render_report(self.config.xml_output, XmlReporter(self),
                                 morfs)
示例#10
0
    def xml_report(self,
                   morfs=None,
                   outfile=None,
                   ignore_errors=None,
                   omit=None,
                   include=None):
        """Generate an XML report of coverage results.

        The report is compatible with Cobertura reports.

        Each module in `morfs` is included in the report.  `outfile` is the
        path to write the file to, "-" will write to stdout.

        See `coverage.report()` for other arguments.

        Returns a float, the total percentage covered.

        """
        self._harvest_data()
        self.config.from_args(
            ignore_errors=ignore_errors,
            omit=omit,
            include=include,
            xml_output=outfile,
        )
        file_to_close = None
        delete_file = False
        if self.config.xml_output:
            if self.config.xml_output == '-':
                outfile = sys.stdout
            else:
                outfile = open(self.config.xml_output, "w")
                file_to_close = outfile
        try:
            try:
                reporter = XmlReporter(self, self.config)
                return reporter.report(morfs, outfile=outfile)
            except CoverageException:
                delete_file = True
                raise
        finally:
            if file_to_close:
                file_to_close.close()
                if delete_file:
                    file_be_gone(self.config.xml_output)
示例#11
0
 def xml_report(self, morfs = None, outfile = None, ignore_errors = None, omit = None, include = None):
     self._harvest_data()
     self.config.from_args(ignore_errors=ignore_errors, omit=omit, include=include, xml_output=outfile)
     file_to_close = None
     delete_file = False
     if self.config.xml_output:
         if self.config.xml_output == '-':
             outfile = sys.stdout
         else:
             outfile = open(self.config.xml_output, 'w')
             file_to_close = outfile
     try:
         reporter = XmlReporter(self, self.config)
         return reporter.report(morfs, outfile=outfile)
     except CoverageException:
         delete_file = True
         raise
     finally:
         if file_to_close:
             file_to_close.close()
             if delete_file:
                 file_be_gone(self.config.xml_output)
示例#12
0
    def run(self) -> int:
        coverage = Coverage()
        coverage.start()
        exit_code = main(['-v', 'tests'])
        coverage.stop()

        # Set score to zero if exit code was non-zero
        if exit_code != 0:
            return 0

        # Generate xml report in StringIO file
        coverage.get_data()
        coverage.config.from_args(
            ignore_errors=None,
            report_omit=None,
            report_include=None,
            xml_output=None,
        )
        data = StringIO()
        reporter = XmlReporter(coverage, coverage.config)
        reporter.report(None, data)
        data.seek(0)

        return round(coverage.report(show_missing=True))