How to use the coverage.data.CoverageData function in coverage

To help you get started, we’ve selected a few coverage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yelp / venv-update / tests / testing / fix_coverage.py View on Github external
def merge_coverage(coverage_data, from_path, to_path):
    new_coverage_data = CoverageData()
    assert coverage_data._filename != new_coverage_data._filename

    for filename in coverage_data.measured_files():
        result_filename = filename.split(from_path)[-1]
        if filename != result_filename:
            result_filename = result_filename.lstrip('/')
            result_filename = os.path.join(to_path, result_filename)
            result_filename = os.path.abspath(result_filename)
            assert os.path.exists(result_filename), result_filename

        new_coverage_data.add_arcs(
            {result_filename: coverage_data.arcs(filename)}
        )

    return new_coverage_data
github danilobellini / pytest-doctest-custom / fix_coverage_path.py View on Github external
Script to update the file paths stored in a single coverage data file

Syntax: python fixpath.py DATA_FILE OLD_PATH NEW_PATH
"""
import sys, os
from coverage.data import CoverageData, PathAliases

coverage_file_name, old_path, new_path = sys.argv[1:]

pa = PathAliases()
pa.add(old_path, new_path)

old_cd = CoverageData()
old_cd.read_file(coverage_file_name)

new_cd = CoverageData()
try:
    new_cd.update(old_cd, pa)
except AttributeError: # Coverage 3.7.1 (CPython 3.2)
    namer = lambda f: os.path.abspath(os.path.expanduser(pa.map(f)))
    new_cd.lines = dict((namer(f), d) for f, d in old_cd.lines.items())
    new_cd.arcs = dict((namer(f), d) for f, d in old_cd.arcs.items())
new_cd.write_file(coverage_file_name)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_update_file_tracer_vs_no_file_tracer(self):
        covdata1 = CoverageData(suffix="1")
        covdata1.add_lines({"p1.html": dict.fromkeys([1, 2, 3])})
        covdata1.add_file_tracers({"p1.html": "html.plugin"})

        covdata2 = CoverageData(suffix="2")
        covdata2.add_lines({"p1.html": dict.fromkeys([1, 2, 3])})

        msg = "Conflicting file tracer name for 'p1.html': u?'html.plugin' vs u?''"
        with self.assertRaisesRegex(CoverageException, msg):
            covdata1.update(covdata2)

        msg = "Conflicting file tracer name for 'p1.html': u?'' vs u?'html.plugin'"
        with self.assertRaisesRegex(CoverageException, msg):
            covdata2.update(covdata1)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_no_duplicate_lines(self):
        covdata = CoverageData()
        covdata.set_context("context1")
        covdata.add_lines(LINES_1)
        covdata.set_context("context2")
        covdata.add_lines(LINES_1)
        self.assertEqual(covdata.lines('a.py'), A_PY_LINES_1)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_writing_and_reading(self):
        covdata1 = CoverageData()
        covdata1.add_lines(DATA_1)
        self.data_files.write(covdata1)

        covdata2 = CoverageData()
        self.data_files.read(covdata2)
        self.assert_summary(covdata2, SUMMARY_1)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_update_lines_empty(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines(LINES_1)

        covdata2 = CoverageData(suffix='2')
        covdata1.update(covdata2)
        self.assert_line_counts(covdata1, SUMMARY_1)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_empty_arc_data_is_false(self):
        covdata = CoverageData()
        covdata.add_arcs({})
        self.assertFalse(covdata)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_read_write_lines(self):
        covdata1 = CoverageData("lines.dat")
        covdata1.add_lines(LINES_1)
        covdata1.write()

        covdata2 = CoverageData("lines.dat")
        covdata2.read()
        self.assert_lines1_data(covdata2)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_update_lines(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines(LINES_1)

        covdata2 = CoverageData(suffix='2')
        covdata2.add_lines(LINES_2)

        covdata3 = CoverageData(suffix='3')
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assert_line_counts(covdata3, SUMMARY_1_2)
        self.assert_measured_files(covdata3, MEASURED_FILES_1_2)
github nedbat / coveragepy / tests / test_data.py View on Github external
def test_combining_with_aliases(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines({
            '/home/ned/proj/src/a.py': {1: None, 2: None},
            '/home/ned/proj/src/sub/b.py': {3: None},
            '/home/ned/proj/src/template.html': {10: None},
        })
        covdata1.add_file_tracers({
            '/home/ned/proj/src/template.html': 'html.plugin',
        })
        covdata1.write()

        covdata2 = CoverageData(suffix='2')
        covdata2.add_lines({
            r'c:\ned\test\a.py': {4: None, 5: None},
            r'c:\ned\test\sub\b.py': {3: None, 6: None},
        })
        covdata2.write()