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


Python coverage.Coverage方法代码示例

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


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

示例1: _cover_all_imports

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def _cover_all_imports(main_repo):
  # If our process is supposed to collect coverage for all recipe module
  # imports, do that after we recieve the first Description. This way we can
  # reply to the main process with an Outcome. Otherwise the main process
  # could be blocked on writing a Description while we're trying to write an
  # Outcome.
  if not main_repo.modules:
    # Prevents a coverage warning when there are no modules to collect coverage
    # from.
    return coverage.CoverageData()

  mod_dir_base = os.path.join(main_repo.recipes_root_path, 'recipe_modules')
  cov = coverage.Coverage(config_file=False, include=[
    os.path.join(mod_dir_base, '*', '*.py')
  ])
  cov.start()
  for module in main_repo.modules.itervalues():
    # Allow exceptions to raise here; they'll be reported as a 'global'
    # failure.
    module.do_import()
  cov.stop()
  return cov.get_data()

# administrative stuff (main, pipe handling, etc.) 
开发者ID:luci,项目名称:recipes-py,代码行数:26,代码来源:runner.py

示例2: _get_cov_obj

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [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

示例3: get_total

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def get_total():
    """
    Return the rounded total as properly rounded string.
    """
    cov = coverage.Coverage()
    cov.load()
    total = cov.report(file=Devnull())

    class Precision(coverage.results.Numbers):
        """
        A class for using the percentage rounding of the main coverage package,
        with any percentage.

        To get the string format of the percentage, use the ``pc_covered_str``
        property.

        """
        def __init__(self, percent):
            self.percent = percent

        @property
        def pc_covered(self):
            return self.percent

    return Precision(total).pc_covered_str 
开发者ID:dbrgn,项目名称:coverage-badge,代码行数:27,代码来源:__main__.py

示例4: test_dotpy_not_python_ignored

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_dotpy_not_python_ignored(self):
        self.make_file("main.py", "import innocuous")
        self.make_file("innocuous.py", "a = 2")
        cov = coverage.Coverage()
        self.start_import_stop(cov, "main")
        self.make_file("innocuous.py", "<h1>This isn't python!</h1>")
        cov.html_report(ignore_errors=True)
        self.assertEqual(
            len(cov._warnings),
            1,
            "Expected a warning to be thrown when an invalid python file is parsed")
        self.assertIn(
            "Could not parse Python file",
            cov._warnings[0],
            "Warning message should be in 'invalid file' warning"
        )
        self.assertIn(
            "innocuous.py",
            cov._warnings[0],
            "Filename should be in 'invalid file' warning"
        )
        self.assert_exists("htmlcov/index.html")
        # This would be better as a glob, if the HTML layout changes:
        self.assert_doesnt_exist("htmlcov/innocuous.html") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:26,代码来源:test_html.py

示例5: test_copying_static_files_from_system_in_dir

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_copying_static_files_from_system_in_dir(self):
        # Make a new place for static files.
        INSTALLED = [
            "jquery/jquery.min.js",
            "jquery-hotkeys/jquery.hotkeys.js",
            "jquery-isonscreen/jquery.isonscreen.js",
            "jquery-tablesorter/jquery.tablesorter.min.js",
        ]
        for fpath in INSTALLED:
            self.make_file(os.path.join("static_here", fpath), "Not real.")
        coverage.html.STATIC_PATH.insert(0, "static_here")

        self.make_file("main.py", "print(17)")
        cov = coverage.Coverage()
        self.start_import_stop(cov, "main")
        cov.html_report()

        for fpath in INSTALLED:
            the_file = os.path.basename(fpath)
            with open(os.path.join("htmlcov", the_file)) as f:
                contents = f.read()
            self.assertEqual(contents, "Not real.") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:test_html.py

示例6: test_isolatin1

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_isolatin1(self):
        self.output_dir("out/isolatin1")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import isolatin1            # pragma: nested
            cov.stop()                  # pragma: nested
            cov.html_report(isolatin1, directory="../out/isolatin1")

        compare("gold_isolatin1", "out/isolatin1", size_within=10, file_pattern="*.html")
        contains(
            "out/isolatin1/isolatin1_py.html",
            '<span class="str">"3&#215;4 = 12, &#247;2 = 6&#177;0"</span>',
        ) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:18,代码来源:test_html.py

示例7: test_other

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_other(self):
        self.output_dir("out/other")

        with change_dir("src"):
            # pylint: disable=import-error
            sys.path.insert(0, "../othersrc")
            cov = coverage.Coverage(include=["./*", "../othersrc/*"])
            cov.start()
            import here         # pragma: nested # pylint: disable=unused-variable
            cov.stop()          # pragma: nested
            cov.html_report(directory="../out/other")

        # Different platforms will name the "other" file differently. Rename it
        for p in glob.glob("out/other/*_other_py.html"):
            os.rename(p, "out/other/blah_blah_other_py.html")

        compare("gold_other", "out/other", size_within=10, file_pattern="*.html")
        contains(
            "out/other/index.html",
            '<a href="here_py.html">here.py</a>',
            'other_py.html">', 'other.py</a>',
        ) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:test_html.py

示例8: test_tabbed

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_tabbed(self):
        self.output_dir("out/tabbed")

        with change_dir("src"):
            # pylint: disable=import-error
            cov = coverage.Coverage()
            cov.start()
            import tabbed           # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(tabbed, directory="../out/tabbed")

        # Editors like to change things, make sure our source file still has tabs.
        contains("src/tabbed.py", "\tif x:\t\t\t\t\t# look nice")

        contains(
            "out/tabbed/tabbed_py.html",
            '>        <span class="key">if</span> '
            '<span class="nam">x</span><span class="op">:</span>'
            '                                   '
            '<span class="com"># look nice</span>'
        )

        doesnt_contain("out/tabbed/tabbed_py.html", "\t") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_html.py

示例9: test_unicode

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_unicode(self):
        self.output_dir("out/unicode")

        with change_dir("src"):
            # pylint: disable=import-error, redefined-builtin
            cov = coverage.Coverage()
            cov.start()
            import unicode          # pragma: nested
            cov.stop()              # pragma: nested
            cov.html_report(unicode, directory="../out/unicode")

        compare("gold_unicode", "out/unicode", size_within=10, file_pattern="*.html")
        contains(
            "out/unicode/unicode_py.html",
            '<span class="str">"&#654;d&#729;&#477;b&#592;&#633;&#477;&#652;o&#596;"</span>',
        )

        contains_any(
            "out/unicode/unicode_py.html",
            '<span class="str">"db40,dd00: x&#56128;&#56576;"</span>',
            '<span class="str">"db40,dd00: x&#917760;"</span>',
        ) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:test_html.py

示例10: test_warn_preimported

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_warn_preimported(self):
        self.make_file("hello.py", """\
            import goodbye
            import coverage
            cov = coverage.Coverage(include=["good*"], check_preimported=True)
            cov.start()
            print(goodbye.f())
            cov.stop()
            """)
        self.make_file("goodbye.py", """\
            def f():
                return "Goodbye!"
            """)
        goodbye_path = os.path.abspath("goodbye.py")

        out = self.run_command("python hello.py")
        self.assertIn("Goodbye!", out)

        msg = (
            "Coverage.py warning: "
            "Already imported a file that will be measured: {0} "
            "(already-imported)").format(goodbye_path)
        self.assertIn(msg, out) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:25,代码来源:test_process.py

示例11: test_include_can_measure_stdlib

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_include_can_measure_stdlib(self):
        self.make_file("mymain.py", """\
            import colorsys, random
            a = 1
            r, g, b = [random.random() for _ in range(3)]
            hls = colorsys.rgb_to_hls(r, g, b)
            """)

        # Measure without the stdlib, but include colorsys.
        cov1 = coverage.Coverage(cover_pylib=False, include=["*/colorsys.py"])
        self.start_import_stop(cov1, "mymain")

        # some statements were marked executed in colorsys.py
        _, statements, missing, _ = cov1.analysis("colorsys.py")
        self.assertNotEqual(statements, missing)
        # but none were in random.py
        _, statements, missing, _ = cov1.analysis("random.py")
        self.assertEqual(statements, missing) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:20,代码来源:test_api.py

示例12: test_combining_corrupt_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_combining_corrupt_data(self):
        # If you combine a corrupt data file, then you will get a warning,
        # and the file will remain.
        self.make_good_data_files()
        self.make_bad_data_file()
        cov = coverage.Coverage()
        warning_regex = (
            r"Couldn't read data from '.*\.coverage\.foo': "
            r"CoverageException: Doesn't seem to be a coverage\.py data file"
        )
        with self.assert_warnings(cov, [warning_regex]):
            cov.combine()

        # We got the results from code1 and code2 properly.
        self.check_code1_code2(cov)

        # The bad file still exists.
        self.assert_exists(".coverage.foo") 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:20,代码来源:test_api.py

示例13: test_combining_twice

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_combining_twice(self):
        self.make_good_data_files()
        cov1 = coverage.Coverage()
        cov1.combine()
        cov1.save()
        self.check_code1_code2(cov1)

        cov2 = coverage.Coverage()
        with self.assertRaisesRegex(CoverageException, r"No data to combine"):
            cov2.combine(strict=True)

        cov3 = coverage.Coverage()
        cov3.combine()
        # Now the data is empty!
        _, statements, missing, _ = cov3.analysis("code1.py")
        self.assertEqual(statements, [1])
        self.assertEqual(missing, [1])
        _, statements, missing, _ = cov3.analysis("code2.py")
        self.assertEqual(statements, [1, 2])
        self.assertEqual(missing, [1, 2]) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:22,代码来源:test_api.py

示例14: test_warnings

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_warnings(self):
        self.make_file("hello.py", """\
            import sys, os
            print("Hello")
            """)
        cov = coverage.Coverage(source=["sys", "xyzzy", "quux"])
        self.start_import_stop(cov, "hello")
        cov.get_data()

        out = self.stdout()
        self.assertIn("Hello\n", out)

        err = self.stderr()
        self.assertIn(textwrap.dedent("""\
            Coverage.py warning: Module sys has no Python source. (module-not-python)
            Coverage.py warning: Module xyzzy was never imported. (module-not-imported)
            Coverage.py warning: Module quux was never imported. (module-not-imported)
            Coverage.py warning: No data was collected. (no-data-collected)
            """), err) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:21,代码来源:test_api.py

示例15: test_warnings_suppressed

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import Coverage [as 别名]
def test_warnings_suppressed(self):
        self.make_file("hello.py", """\
            import sys, os
            print("Hello")
            """)
        self.make_file(".coveragerc", """\
            [run]
            disable_warnings = no-data-collected, module-not-imported
            """)
        cov = coverage.Coverage(source=["sys", "xyzzy", "quux"])
        self.start_import_stop(cov, "hello")
        cov.get_data()

        out = self.stdout()
        self.assertIn("Hello\n", out)

        err = self.stderr()
        self.assertIn(textwrap.dedent("""\
            Coverage.py warning: Module sys has no Python source. (module-not-python)
            """), err)
        self.assertNotIn("module-not-imported", err)
        self.assertNotIn("no-data-collected", err) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:24,代码来源:test_api.py


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