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


Python coverage.CoverageData方法代码示例

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


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

示例1: write_cov_file

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def write_cov_file(line_data: Dict[str, List[int]], fname: str) -> None:
    """Write a coverage file supporting both Coverage v4 and v5.

    Args:
        line_data: Dictionary of line data for the coverage file.
        fname: string filename for output location (absolute path)

    Returns:
        None
    """
    if coverage.version_info[0] == 4:
        covdata = coverage.CoverageData()
        covdata.add_lines(line_data)
        covdata.write_file(fname)

    else:
        # assume coverage v 5
        covdata = coverage.CoverageData(basename=fname)
        covdata.add_lines(line_data)
        covdata.write()


####################################################################################################
# CLI: MOCK ARGS
#################################################################################################### 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:27,代码来源:conftest.py

示例2: _cover_all_imports

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

示例3: get_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def get_data(self):
        """Get the collected data.

        Also warn about various problems collecting data.

        Returns a :class:`coverage.CoverageData`, the collected coverage data.

        .. versionadded:: 4.0

        """
        self._init()

        if self._collector.save_data(self.data):
            self._post_save_work()

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

示例4: test_append_data_with_different_file

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

        self.make_file(".coveragerc", """\
            [run]
            data_file = .mycovdata
            """)

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

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

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

示例5: get_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def get_data(self):
        """Get the collected data.

        Also warn about various problems collecting data.

        Returns a :class:`coverage.CoverageData`, the collected coverage data.

        .. versionadded:: 4.0

        """
        self._init()
        self._init_data(suffix=None)
        self._post_init()

        if self._collector and self._collector.flush_data():
            self._post_save_work()

        return self._data 
开发者ID:nedbat,项目名称:coveragepy,代码行数:20,代码来源:control.py

示例6: test_append_data

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

示例7: test_append_data_with_different_file

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

        self.make_file(".coveragerc", """\
            [run]
            data_file = .mycovdata
            """)

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

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

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

示例8: test_merged_profiles_get_coveragepy_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def test_merged_profiles_get_coveragepy_data():
    from covimerage import MergedProfiles

    m = MergedProfiles([])
    cov_data = m.get_coveragepy_data()
    try:
        from coverage.data import CoverageJsonData
    except ImportError:
        assert isinstance(cov_data, coverage.CoverageData)
    else:
        assert isinstance(cov_data, CoverageJsonData) 
开发者ID:Vimjas,项目名称:covimerage,代码行数:13,代码来源:test_main.py

示例9: save_coverage

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def save_coverage(tree, templates, output_dir, app_name, granularity):
    groups = Utils2.get_groupped_classes(tree)
    init_row = templates['init_row.pt']
    init_table = templates['init_table.pt']
    index_template = templates['index.pt']

    rows = []
    total_coverage_data = CoverageData()
    for g in groups:
        (package, path, coverage_data) = save_package_indexhtml(g, templates, output_dir, app_name, granularity)
        coverage = coverage_data.get_formatted_coverage(granularity)
        row = init_row(elementlink=path, type='package', elementname=package,
                  coverage=coverage,
                  respath='', coverage_data=coverage_data,
                  is_instruction_level=Granularity.is_instruction(granularity),
                  progress_covered=coverage_data.covered(granularity),
                  progress_missed=coverage_data.missed(granularity))
        rows.append(Markup(row))
        total_coverage_data.add_data(coverage_data)
    total_coverage = total_coverage_data.get_formatted_coverage(granularity)
    table = init_table(rows=Markup("\n".join(rows)),
                        total_coverage=total_coverage,
                        total_coverage_data=total_coverage_data,
                        is_instruction_level=Granularity.is_instruction(granularity),
                        progress_covered=total_coverage_data.covered(granularity),
                        progress_all=total_coverage_data.coverable(granularity))
    root_path = ''
    html = index_template(table=Markup(table), appname=app_name, title=app_name, package=None, 
                          respath=root_path, file_name=None, granularity=Granularity.get(granularity))
    path = os.path.join(output_dir, 'index.html')
    with open(path, 'w') as f:
        f.write(html) 
开发者ID:pilgun,项目名称:acvtool,代码行数:34,代码来源:reporter.py

示例10: test_combine_parallel_data

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def test_combine_parallel_data(self):
        self.make_b_or_c_py()
        out = self.run_command("coverage run -p b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        out = self.run_command("coverage run -p b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")

        # After two -p runs, there should be two .coverage.machine.123 files.
        self.assertEqual(self.number_of_data_files(), 2)

        # Combine the parallel coverage data files into .coverage .
        self.run_command("coverage combine")
        self.assert_exists(".coverage")

        # After combining, there should be only the .coverage file.
        self.assertEqual(self.number_of_data_files(), 1)

        # Read the coverage file and see that b_or_c.py has all 7 lines
        # executed.
        data = coverage.CoverageData()
        data.read_file(".coverage")
        self.assertEqual(data.line_counts()['b_or_c.py'], 7)

        # Running combine again should fail, because there are no parallel data
        # files to combine.
        status, out = self.run_command_status("coverage combine")
        self.assertEqual(status, 1)
        self.assertEqual(out, "No data to combine\n")

        # And the originally combined data is still there.
        data = coverage.CoverageData()
        data.read_file(".coverage")
        self.assertEqual(data.line_counts()['b_or_c.py'], 7) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:39,代码来源:test_process.py

示例11: test_combine_parallel_data_with_a_corrupt_file

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def test_combine_parallel_data_with_a_corrupt_file(self):
        self.make_b_or_c_py()
        out = self.run_command("coverage run -p b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        out = self.run_command("coverage run -p b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")

        # After two -p runs, there should be two .coverage.machine.123 files.
        self.assertEqual(self.number_of_data_files(), 2)

        # Make a bogus data file.
        self.make_file(".coverage.bad", "This isn't a coverage data file.")

        # Combine the parallel coverage data files into .coverage .
        out = self.run_command("coverage combine")
        self.assert_exists(".coverage")
        self.assert_exists(".coverage.bad")
        warning_regex = (
            r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad': "
            r"CoverageException: Doesn't seem to be a coverage\.py data file"
        )
        self.assertRegex(out, warning_regex)

        # After combining, those two should be the only data files.
        self.assertEqual(self.number_of_data_files(), 2)

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

示例12: test_combine_no_usable_files

# 需要导入模块: import coverage [as 别名]
# 或者: from coverage import CoverageData [as 别名]
def test_combine_no_usable_files(self):
        # https://bitbucket.org/ned/coveragepy/issues/629/multiple-use-of-combine-leads-to-empty
        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.assertEqual(self.number_of_data_files(), 1)

        # Make bogus data files.
        self.make_file(".coverage.bad1", "This isn't a coverage data file.")
        self.make_file(".coverage.bad2", "This isn't a coverage data file.")

        # Combine the parallel coverage data files into .coverage, but nothing is readable.
        status, out = self.run_command_status("coverage combine")
        self.assertEqual(status, 1)

        for n in "12":
            self.assert_exists(".coverage.bad{0}".format(n))
            warning_regex = (
                r"Coverage.py warning: Couldn't read data from '.*\.coverage\.bad{0}': "
                r"CoverageException: Doesn't seem to be a coverage\.py data file".format(n)
            )
            self.assertRegex(out, warning_regex)
        self.assertRegex(out, r"No usable data files")

        # After combining, we should have a main file and two parallel files.
        self.assertEqual(self.number_of_data_files(), 3)

        # Read the coverage file and see that b_or_c.py has 6 lines
        # executed (we only did b, not c).
        data = coverage.CoverageData()
        data.read_file(".coverage")
        self.assertEqual(data.line_counts()['b_or_c.py'], 6) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:35,代码来源:test_process.py

示例13: test_combine_parallel_data_in_two_steps

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

        out = self.run_command("coverage run -p b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        # Combine the (one) parallel coverage data file into .coverage .
        self.run_command("coverage combine")
        self.assert_exists(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

        out = self.run_command("coverage run -p b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assertEqual(self.number_of_data_files(), 2)

        # Combine the parallel coverage data files into .coverage .
        self.run_command("coverage combine --append")
        self.assert_exists(".coverage")

        # After combining, there should be only the .coverage file.
        self.assertEqual(self.number_of_data_files(), 1)

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

示例14: test_append_can_create_a_data_file

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

        out = self.run_command("coverage run --append b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_exists(".coverage")
        self.assertEqual(self.number_of_data_files(), 1)

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

示例15: test_combine_with_rc

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

        self.make_file(".coveragerc", """\
            [run]
            parallel = true
            """)

        out = self.run_command("coverage run b_or_c.py b")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")

        out = self.run_command("coverage run b_or_c.py c")
        self.assertEqual(out, 'done\n')
        self.assert_doesnt_exist(".coverage")

        # After two runs, there should be two .coverage.machine.123 files.
        self.assertEqual(self.number_of_data_files(), 2)

        # Combine the parallel coverage data files into .coverage .
        self.run_command("coverage combine")
        self.assert_exists(".coverage")
        self.assert_exists(".coveragerc")

        # After combining, there should be only the .coverage file.
        self.assertEqual(self.number_of_data_files(), 1)

        # Read the coverage file and see that b_or_c.py has all 7 lines
        # executed.
        data = coverage.CoverageData()
        data.read_file(".coverage")
        self.assertEqual(data.line_counts()['b_or_c.py'], 7)

        # Reporting should still work even with the .rc file
        out = self.run_command("coverage report")
        self.assertMultiLineEqual(out, textwrap.dedent("""\
            Name        Stmts   Miss  Cover
            -------------------------------
            b_or_c.py       7      0   100%
            """)) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:42,代码来源:test_process.py


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