当前位置: 首页>>代码示例>>Python>>正文


Python coverage.data方法代码示例

本文整理汇总了Python中coverage.data方法的典型用法代码示例。如果您正苦于以下问题:Python coverage.data方法的具体用法?Python coverage.data怎么用?Python coverage.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coverage的用法示例。


在下文中一共展示了coverage.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_cov_obj

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def _get_cov_obj(self):
        class CoverageW(coverage.Coverage):
            """Wrap/shortcut _get_file_reporter to return ours."""
            def _get_file_reporter(self, morf):
                return FileReporter(morf)

        cov_coverage = CoverageW(
            config_file=True if self.config_file is None else self.config_file,
        )
        cov_coverage._init()
        if hasattr(cov_coverage, '_data'):
            # coveragepy 5
            # TODO: get rid of intermediate handling of CoverageData?
            cov_coverage._data = self.data.cov_data
        else:
            cov_coverage.data = self.data.cov_data
        return cov_coverage 
开发者ID:Vimjas,项目名称:covimerage,代码行数:19,代码来源:coveragepy.py

示例2: _post_save_work

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def _post_save_work(self):
        """After saving data, look for warnings, post-work, etc.

        Warn about things that should have happened but didn't.
        Look for unexecuted files.

        """
        # If there are still entries in the source_pkgs_unmatched list,
        # then we never encountered those packages.
        if self._warn_unimported_source:
            self._inorout.warn_unimported_source()

        # Find out if we got any data.
        if not self.data and self._warn_no_data:
            self._warn("No data was collected.", slug="no-data-collected")

        # Find files that were never executed at all.
        for file_path, plugin_name in self._inorout.find_unexecuted_files():
            self.data.touch_file(file_path, plugin_name)

        if self.config.note:
            self.data.add_run_info(note=self.config.note)

    # Backward compatibility with version 1. 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:26,代码来源:control.py

示例3: _get_file_reporter

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def _get_file_reporter(self, morf):
        """Get a FileReporter for a module or file name."""
        plugin = None
        file_reporter = "python"

        if isinstance(morf, string_class):
            abs_morf = abs_file(morf)
            plugin_name = self.data.file_tracer(abs_morf)
            if plugin_name:
                plugin = self._plugins.get(plugin_name)

        if plugin:
            file_reporter = plugin.file_reporter(abs_morf)
            if file_reporter is None:
                raise CoverageException(
                    "Plugin %r did not provide a file reporter for %r." % (
                        plugin._coverage_plugin_name, morf
                    )
                )

        if file_reporter == "python":
            file_reporter = PythonFileReporter(morf, self)

        return file_reporter 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:26,代码来源:control.py

示例4: _get_file_reporters

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def _get_file_reporters(self, morfs=None):
        """Get a list of FileReporters for a list of modules or file names.

        For each module or file name in `morfs`, find a FileReporter.  Return
        the list of FileReporters.

        If `morfs` is a single module or file name, this returns a list of one
        FileReporter.  If `morfs` is empty or None, then the list of all files
        measured is used to find the FileReporters.

        """
        if not morfs:
            morfs = self.data.measured_files()

        # Be sure we have a list.
        if not isinstance(morfs, (list, tuple)):
            morfs = [morfs]

        file_reporters = []
        for morf in morfs:
            file_reporter = self._get_file_reporter(morf)
            file_reporters.append(file_reporter)

        return file_reporters 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:26,代码来源:control.py

示例5: test_debug_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_debug_data(self):
        data = CoverageData()
        data.add_lines({
            "file1.py": dict.fromkeys(range(1, 18)),
            "file2.py": dict.fromkeys(range(1, 24)),
        })
        data.add_file_tracers({"file1.py": "a_plugin"})
        data_files = CoverageDataFiles()
        data_files.write(data)

        self.command_line("debug data")
        self.assertMultiLineEqual(self.stdout(), textwrap.dedent("""\
            -- data ------------------------------------------------------
            path: FILENAME
            has_arcs: False

            2 files:
            file1.py: 17 lines [a_plugin]
            file2.py: 23 lines
            """).replace("FILENAME", data_files.filename)) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:22,代码来源:test_cmdline.py

示例6: test_run_omit_vs_report_omit

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_run_omit_vs_report_omit(self):
        # https://bitbucket.org/ned/coveragepy/issues/622/report-omit-overwrites-run-omit
        # report:omit shouldn't clobber run:omit.
        self.make_mycode()
        self.make_file(".coveragerc", """\
            [run]
            omit = */covmodzip1.py

            [report]
            omit = */covmod1.py
            """)
        self.run_command("coverage run mycode.py")

        # Read the data written, to see that the right files have been omitted from running.
        covdata = CoverageData()
        covdata.read_file(".coverage")
        files = [os.path.basename(p) for p in covdata.measured_files()]
        self.assertIn("covmod1.py", files)
        self.assertNotIn("covmodzip1.py", files) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:21,代码来源:test_summary.py

示例7: test_dotpy_not_python

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_dotpy_not_python(self):
        # We run a .py file, and when reporting, we can't parse it as Python.
        # We should get an error message in the report.

        self.make_mycode()
        self.run_command("coverage run mycode.py")
        self.make_file("mycode.py", "This isn't python at all!")
        report = self.report_from_command("coverage report mycode.py")

        # mycode   NotPython: Couldn't parse '...' as Python source: 'invalid syntax' at line 1
        # Name     Stmts   Miss  Cover
        # ----------------------------
        # No data to report.

        errmsg = self.squeezed_lines(report)[0]
        # The actual file name varies run to run.
        errmsg = re.sub(r"parse '.*mycode.py", "parse 'mycode.py", errmsg)
        # The actual error message varies version to version
        errmsg = re.sub(r": '.*' at", ": 'error' at", errmsg)
        self.assertEqual(
            errmsg,
            "mycode.py NotPython: Couldn't parse 'mycode.py' as Python source: 'error' at line 1"
        ) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_summary.py

示例8: test_dothtml_not_python

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_dothtml_not_python(self):
        # We run a .html file, and when reporting, we can't parse it as
        # Python.  Since it wasn't .py, no error is reported.

        # Run an "html" file
        self.make_file("mycode.html", "a = 1")
        self.run_command("coverage run mycode.html")
        # Before reporting, change it to be an HTML file.
        self.make_file("mycode.html", "<h1>This isn't python at all!</h1>")
        report = self.report_from_command("coverage report mycode.html")

        # Name     Stmts   Miss  Cover
        # ----------------------------
        # No data to report.

        self.assertEqual(self.line_count(report), 3)
        self.assertIn('No data to report.', report) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:19,代码来源:test_summary.py

示例9: report

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def report(self, morfs):
        """Generate an HTML report for `morfs`.

        `morfs` is a list of modules or file names.

        """
        # Read the status data and check that this run used the same
        # global data as the last run.
        self.incr.read()
        self.incr.check_global_data(self.config, self.pyfile_html_source)

        # Process all the files.
        for fr, analysis in get_analysis_to_report(self.coverage, morfs):
            self.html_file(fr, analysis)

        if not self.all_files_nums:
            raise CoverageException("No data to report.")

        self.totals = sum(self.all_files_nums)

        # Write the index file.
        self.index_file()

        self.make_local_static_report_files()
        return self.totals.n_statements and self.totals.pc_covered 
开发者ID:nedbat,项目名称:coveragepy,代码行数:27,代码来源:html.py

示例10: can_skip_file

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def can_skip_file(self, data, fr, rootname):
        """Can we skip reporting this file?

        `data` is a CoverageData object, `fr` is a `FileReporter`, and
        `rootname` is the name being used for the file.
        """
        m = Hasher()
        m.update(fr.source().encode('utf-8'))
        add_data_to_hash(data, fr.filename, m)
        this_hash = m.hexdigest()

        that_hash = self.file_hash(rootname)

        if this_hash == that_hash:
            # Nothing has changed to require the file to be reported again.
            return True
        else:
            self.set_file_hash(rootname, this_hash)
            return False 
开发者ID:nedbat,项目名称:coveragepy,代码行数:21,代码来源:html.py

示例11: switch_context

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def switch_context(self, new_context):
        """Switch to a new dynamic context.

        `new_context` is a string to use as the :ref:`dynamic context
        <dynamic_contexts>` label for collected data.  If a :ref:`static
        context <static_contexts>` is in use, the static and dynamic context
        labels will be joined together with a pipe character.

        Coverage collection must be started already.

        .. versionadded:: 5.0

        """
        if not self._started:                           # pragma: part started
            raise CoverageException(
                "Cannot switch context, coverage is not started"
                )

        if self._collector.should_start_context:
            self._warn("Conflicting dynamic contexts", slug="dynamic-conflict", once=True)

        self._collector.switch_context(new_context) 
开发者ID:nedbat,项目名称:coveragepy,代码行数:24,代码来源:control.py

示例12: analysis2

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def analysis2(self, morf):
        """Analyze a module.

        `morf` is a module or a file name.  It will be analyzed to determine
        its coverage statistics.  The return value is a 5-tuple:

        * The file name for the module.
        * A list of line numbers of executable statements.
        * A list of line numbers of excluded statements.
        * A list of line numbers of statements not run (missing from
          execution).
        * A readable formatted string of the missing line numbers.

        The analysis uses the source file itself and the current measured
        coverage data.

        """
        analysis = self._analyze(morf)
        return (
            analysis.filename,
            sorted(analysis.statements),
            sorted(analysis.excluded),
            sorted(analysis.missing),
            analysis.missing_formatted(),
            ) 
开发者ID:nedbat,项目名称:coveragepy,代码行数:27,代码来源:control.py

示例13: _analyze

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        # All reporting comes through here, so do reporting initialization.
        self._init()
        Numbers.set_precision(self.config.precision)
        self._post_init()

        data = self.get_data()
        if not isinstance(it, FileReporter):
            it = self._get_file_reporter(it)

        return Analysis(data, it, self._file_mapper) 
开发者ID:nedbat,项目名称:coveragepy,代码行数:18,代码来源:control.py

示例14: test_append_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_append_data(self):
        self.make_b_or_c_py()

        out = self.run_command("coverage run b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assert_file_count(".coverage.*", 0)

        out = self.run_command("coverage run --append b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assert_file_count(".coverage.*", 0)

        # Read the coverage file and see that b_or_c.py has all 8 lines
        # executed.
        data = coverage.CoverageData()
        data.read()
        self.assertEqual(line_counts(data)['b_or_c.py'], 8) 
开发者ID:nedbat,项目名称:coveragepy,代码行数:20,代码来源:test_process.py

示例15: test_erase_parallel

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import data [as 别名]
def test_erase_parallel(self):
        self.make_file(".coveragerc", """\
            [run]
            data_file = data.dat
            parallel = True
            """)
        self.make_file("data.dat")
        self.make_file("data.dat.fooey")
        self.make_file("data.dat.gooey")
        self.make_file(".coverage")

        self.run_command("coverage erase")
        self.assert_doesnt_exist("data.dat")
        self.assert_doesnt_exist("data.dat.fooey")
        self.assert_doesnt_exist("data.dat.gooey")
        self.assert_exists(".coverage") 
开发者ID:nedbat,项目名称:coveragepy,代码行数:18,代码来源:test_process.py


注:本文中的coverage.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。