コード例 #1
0
    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)
コード例 #2
0
ファイル: test_data.py プロジェクト: ziadsawalha/coveragepy
    def test_update_file_tracers(self):
        covdata1 = CoverageData()
        covdata1.set_lines({
            "p1.html": dict.fromkeys([1, 2, 3, 4]),
            "p2.html": dict.fromkeys([5, 6, 7]),
            "main.py": dict.fromkeys([10, 11, 12]),
        })
        covdata1.set_file_tracers({
            "p1.html": "html.plugin",
            "p2.html": "html.plugin2",
        })

        covdata2 = CoverageData()
        covdata2.set_lines({
            "p1.html": dict.fromkeys([3, 4, 5, 6]),
            "p2.html": dict.fromkeys([7, 8, 9]),
            "p3.foo": dict.fromkeys([1000, 1001]),
            "main.py": dict.fromkeys([10, 11, 12]),
        })
        covdata2.set_file_tracers({
            "p1.html": "html.plugin",
            "p2.html": "html.plugin2",
            "p3.foo": "foo_plugin",
        })

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)
        self.assertEqual(covdata3.file_tracer("p1.html"), "html.plugin")
        self.assertEqual(covdata3.file_tracer("p2.html"), "html.plugin2")
        self.assertEqual(covdata3.file_tracer("p3.foo"), "foo_plugin")
        self.assertEqual(covdata3.file_tracer("main.py"), "")
コード例 #3
0
    def test_combining_arc_contexts(self):
        red_data, blue_data = self.run_red_blue(branch=True)
        for datas in [[red_data, blue_data], [blue_data, red_data]]:
            combined = CoverageData(suffix="combined")
            for data in datas:
                combined.update(data)

            self.assertEqual(combined.measured_contexts(), {'red', 'blue'})

            full_names = {os.path.basename(f): f for f in combined.measured_files()}
            self.assertCountEqual(full_names, ['red.py', 'blue.py'])

            fred = full_names['red.py']
            fblue = full_names['blue.py']

            def assert_combined_lines(filename, context, lines):
                # pylint: disable=cell-var-from-loop
                combined.set_query_context(context)
                self.assertEqual(combined.lines(filename), lines)

            assert_combined_lines(fred, 'red', self.LINES)
            assert_combined_lines(fred, 'blue', [])
            assert_combined_lines(fblue, 'red', [])
            assert_combined_lines(fblue, 'blue', self.LINES)

            def assert_combined_arcs(filename, context, lines):
                # pylint: disable=cell-var-from-loop
                combined.set_query_context(context)
                self.assertEqual(combined.arcs(filename), lines)

            assert_combined_arcs(fred, 'red', self.ARCS)
            assert_combined_arcs(fred, 'blue', [])
            assert_combined_arcs(fblue, 'red', [])
            assert_combined_arcs(fblue, 'blue', self.ARCS)
コード例 #4
0
    def test_update_arcs_empty(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_arcs(ARCS_3)

        covdata2 = CoverageData(suffix='2')
        covdata1.update(covdata2)
        self.assert_line_counts(covdata1, SUMMARY_3)
コード例 #5
0
ファイル: test_data.py プロジェクト: ionelmc/coveragepy
    def test_update_file_tracers(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines({
            "p1.html": dict.fromkeys([1, 2, 3, 4]),
            "p2.html": dict.fromkeys([5, 6, 7]),
            "main.py": dict.fromkeys([10, 11, 12]),
        })
        covdata1.add_file_tracers({
            "p1.html": "html.plugin",
            "p2.html": "html.plugin2",
        })

        covdata2 = CoverageData(suffix='2')
        covdata2.add_lines({
            "p1.html": dict.fromkeys([3, 4, 5, 6]),
            "p2.html": dict.fromkeys([7, 8, 9]),
            "p3.foo": dict.fromkeys([1000, 1001]),
            "main.py": dict.fromkeys([10, 11, 12]),
        })
        covdata2.add_file_tracers({
            "p1.html": "html.plugin",
            "p2.html": "html.plugin2",
            "p3.foo": "foo_plugin",
        })

        covdata3 = CoverageData(suffix='3')
        covdata3.update(covdata1)
        covdata3.update(covdata2)
        self.assertEqual(covdata3.file_tracer("p1.html"), "html.plugin")
        self.assertEqual(covdata3.file_tracer("p2.html"), "html.plugin2")
        self.assertEqual(covdata3.file_tracer("p3.foo"), "foo_plugin")
        self.assertEqual(covdata3.file_tracer("main.py"), "")
コード例 #6
0
    def test_combining_line_contexts(self):
        red_data, blue_data = self.run_red_blue()
        for datas in [[red_data, blue_data], [blue_data, red_data]]:
            combined = CoverageData(suffix="combined")
            for data in datas:
                combined.update(data)

            assert combined.measured_contexts() == {'red', 'blue'}

            full_names = {
                os.path.basename(f): f
                for f in combined.measured_files()
            }
            assert_count_equal(full_names, ['red.py', 'blue.py'])

            fred = full_names['red.py']
            fblue = full_names['blue.py']

            def assert_combined_lines(filename, context, lines):
                # pylint: disable=cell-var-from-loop
                combined.set_query_context(context)
                assert combined.lines(filename) == lines

            assert_combined_lines(fred, 'red', self.LINES)
            assert_combined_lines(fred, 'blue', [])
            assert_combined_lines(fblue, 'red', [])
            assert_combined_lines(fblue, 'blue', self.LINES)
コード例 #7
0
    def test_combining_arc_contexts(self):
        red_data, blue_data = self.run_red_blue(branch=True)
        for datas in [[red_data, blue_data], [blue_data, red_data]]:
            combined = CoverageData(suffix="combined")
            for data in datas:
                combined.update(data)

            self.assertEqual(combined.measured_contexts(), {'red', 'blue'})

            full_names = {
                os.path.basename(f): f
                for f in combined.measured_files()
            }
            self.assertCountEqual(full_names, ['red.py', 'blue.py'])

            fred = full_names['red.py']
            fblue = full_names['blue.py']

            self.assertEqual(combined.lines(fred, contexts=['red']),
                             self.LINES)
            self.assertEqual(combined.lines(fred, contexts=['blue']), [])
            self.assertEqual(combined.lines(fblue, contexts=['red']), [])
            self.assertEqual(combined.lines(fblue, contexts=['blue']),
                             self.LINES)

            self.assertEqual(combined.arcs(fred, contexts=['red']), self.ARCS)
            self.assertEqual(combined.arcs(fred, contexts=['blue']), [])
            self.assertEqual(combined.arcs(fblue, contexts=['red']), [])
            self.assertEqual(combined.arcs(fblue, contexts=['blue']),
                             self.ARCS)
コード例 #8
0
def apply_path_aliases(cov, alias_map):
    """Adjust filenames in coverage data."""
    data = CoverageData()
    aliases = PathAliases()
    for k, v in alias_map.items():
        aliases.add(k, v)
    data.update(cov.data, aliases)
    cov.data = data
コード例 #9
0
    def test_update_cant_mix_lines_and_arcs(self):
        covdata1 = CoverageData()
        covdata1.add_lines(LINES_1)

        covdata2 = CoverageData()
        covdata2.add_arcs(ARCS_3)

        with self.assertRaisesRegex(CoverageException, "Can't combine arc data with line data"):
            covdata1.update(covdata2)

        with self.assertRaisesRegex(CoverageException, "Can't combine line data with arc data"):
            covdata2.update(covdata1)
コード例 #10
0
ファイル: test_data.py プロジェクト: ziadsawalha/coveragepy
    def test_update_cant_mix_lines_and_arcs(self):
        covdata1 = CoverageData()
        covdata1.set_lines(LINES_1)

        covdata2 = CoverageData()
        covdata2.set_arcs(ARCS_3)

        with self.assertRaisesRegex(CoverageException, "Can't combine arc data with line data"):
            covdata1.update(covdata2)

        with self.assertRaisesRegex(CoverageException, "Can't combine line data with arc data"):
            covdata2.update(covdata1)
コード例 #11
0
    def test_update_cant_mix_lines_and_arcs(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_lines(LINES_1)

        covdata2 = CoverageData(suffix='2')
        covdata2.add_arcs(ARCS_3)

        with pytest.raises(CoverageException, match="Can't combine arc data with line data"):
            covdata1.update(covdata2)

        with pytest.raises(CoverageException, match="Can't combine line data with arc data"):
            covdata2.update(covdata1)
コード例 #12
0
ファイル: fix-coverage-paths.py プロジェクト: piratos/e3-core
def fix_paths(site_pkg_dir, cov_data_file):
    site_pkg_dir = os.path.abspath(site_pkg_dir)

    paths = PathAliases()
    paths.add(site_pkg_dir, '.')

    old_coverage_data = CoverageData()
    old_coverage_data.read_file(cov_data_file)

    new_coverage_data = CoverageData()
    new_coverage_data.update(old_coverage_data, paths)

    new_coverage_data.write_file(cov_data_file)
コード例 #13
0
    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)
コード例 #14
0
    def test_update_arcs(self):
        covdata1 = CoverageData(suffix='1')
        covdata1.add_arcs(ARCS_3)

        covdata2 = CoverageData(suffix='2')
        covdata2.add_arcs(ARCS_4)

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

        self.assert_line_counts(covdata3, SUMMARY_3_4)
        self.assert_measured_files(covdata3, MEASURED_FILES_3_4)
コード例 #15
0
ファイル: test_data.py プロジェクト: jayhetee/coveragepy
    def test_update_lines(self):
        covdata1 = CoverageData()
        covdata1.set_lines(LINES_1)

        covdata2 = CoverageData()
        covdata2.set_lines(LINES_2)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assert_line_counts(covdata3, SUMMARY_1_2)
        self.assert_measured_files(covdata3, MEASURED_FILES_1_2)
        self.assertEqual(covdata3.run_infos(), [])
コード例 #16
0
ファイル: test_data.py プロジェクト: mociepka/coveragepy
    def test_update_lines(self):
        covdata1 = CoverageData()
        covdata1.add_lines(LINES_1)

        covdata2 = CoverageData()
        covdata2.add_lines(LINES_2)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assert_line_counts(covdata3, SUMMARY_1_2)
        self.assert_measured_files(covdata3, MEASURED_FILES_1_2)
        self.assertEqual(covdata3.run_infos(), [])
コード例 #17
0
ファイル: test_data.py プロジェクト: ziadsawalha/coveragepy
    def test_update_arcs(self):
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)

        covdata2 = CoverageData()
        covdata2.set_arcs(ARCS_4)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assert_line_counts(covdata3, SUMMARY_3_4)
        self.assert_measured_files(covdata3, MEASURED_FILES_3_4)
        self.assertEqual(covdata3.run_infos(), [])
コード例 #18
0
ファイル: test_data.py プロジェクト: federicobond/coveragepy
    def test_update_arcs(self):
        covdata1 = CoverageData()
        covdata1.add_arcs(ARCS_3)

        covdata2 = CoverageData()
        covdata2.add_arcs(ARCS_4)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assert_line_counts(covdata3, SUMMARY_3_4)
        self.assert_measured_files(covdata3, MEASURED_FILES_3_4)
        self.assertEqual(covdata3.run_infos(), [])
コード例 #19
0
ファイル: test_data.py プロジェクト: ionelmc/coveragepy
    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)
コード例 #20
0
ファイル: test_data.py プロジェクト: ziadsawalha/coveragepy
    def test_update_file_tracer_vs_no_file_tracer(self):
        covdata1 = CoverageData()
        covdata1.set_lines({"p1.html": dict.fromkeys([1, 2, 3])})
        covdata1.set_file_tracers({"p1.html": "html.plugin"})

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

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

        msg = "Conflicting file tracer name for 'p1.html': '' vs 'html.plugin'"
        with self.assertRaisesRegex(CoverageException, msg):
            covdata2.update(covdata1)
コード例 #21
0
ファイル: test_data.py プロジェクト: hugovk/coveragepy
    def test_update_conflicting_file_tracers(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])})
        covdata2.add_file_tracers({"p1.html": "html.other_plugin"})

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

        msg = "Conflicting file tracer name for 'p1.html': u?'html.other_plugin' vs u?'html.plugin'"
        with self.assertRaisesRegex(CoverageException, msg):
            covdata2.update(covdata1)
コード例 #22
0
    def test_update_conflicting_file_tracers(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])})
        covdata2.add_file_tracers({"p1.html": "html.other_plugin"})

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

        msg = "Conflicting file tracer name for 'p1.html': u?'html.other_plugin' vs u?'html.plugin'"
        with pytest.raises(CoverageException, match=msg):
            covdata2.update(covdata1)
コード例 #23
0
ファイル: test_data.py プロジェクト: federicobond/coveragepy
    def test_update_conflicting_file_tracers(self):
        covdata1 = CoverageData()
        covdata1.add_lines({"p1.html": dict.fromkeys([1, 2, 3])})
        covdata1.add_file_tracers({"p1.html": "html.plugin"})

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

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

        msg = "Conflicting file tracer name for 'p1.html': 'html.other_plugin' vs 'html.plugin'"
        with self.assertRaisesRegex(CoverageException, msg):
            covdata2.update(covdata1)
コード例 #24
0
    def test_update_run_info(self):
        covdata1 = CoverageData()
        covdata1.add_arcs(ARCS_3)
        covdata1.add_run_info(hello="there", count=17)

        covdata2 = CoverageData()
        covdata2.add_arcs(ARCS_4)
        covdata2.add_run_info(hello="goodbye", count=23)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assertEqual(covdata3.run_infos(), [
            {'hello': 'there', 'count': 17},
            {'hello': 'goodbye', 'count': 23},
        ])
コード例 #25
0
ファイル: test_data.py プロジェクト: ziadsawalha/coveragepy
    def test_update_run_info(self):
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)
        covdata1.add_run_info(hello="there", count=17)

        covdata2 = CoverageData()
        covdata2.set_arcs(ARCS_4)
        covdata2.add_run_info(hello="goodbye", count=23)

        covdata3 = CoverageData()
        covdata3.update(covdata1)
        covdata3.update(covdata2)

        self.assertEqual(covdata3.run_infos(), [
            {'hello': 'there', 'count': 17},
            {'hello': 'goodbye', 'count': 23},
        ])
コード例 #26
0
ファイル: test_context.py プロジェクト: hugovk/coveragepy
    def test_combining_line_contexts(self):
        red_data, blue_data = self.run_red_blue()
        for datas in [[red_data, blue_data], [blue_data, red_data]]:
            combined = CoverageData(suffix="combined")
            for data in datas:
                combined.update(data)

            self.assertEqual(combined.measured_contexts(), {'red', 'blue'})

            full_names = {os.path.basename(f): f for f in combined.measured_files()}
            self.assertCountEqual(full_names, ['red.py', 'blue.py'])

            fred = full_names['red.py']
            fblue = full_names['blue.py']

            self.assertEqual(combined.lines(fred, context='red'), self.LINES)
            self.assertEqual(combined.lines(fred, context='blue'), [])
            self.assertEqual(combined.lines(fblue, context='red'), [])
            self.assertEqual(combined.lines(fblue, context='blue'), self.LINES)
コード例 #27
0
#!/usr/bin/env python
# By Danilo J. S. Bellini
"""
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)