Пример #1
0
    def test_combining_from_files(self):
        covdata1 = CoverageData()
        covdata1.set_lines(LINES_1)
        os.makedirs('cov1')
        covdata1.write_file('cov1/.coverage.1')

        covdata2 = CoverageData()
        covdata2.set_lines(LINES_2)
        os.makedirs('cov2')
        covdata2.write_file('cov2/.coverage.2')

        # This data won't be included.
        covdata_xxx = CoverageData()
        covdata_xxx.set_arcs(ARCS_3)
        covdata_xxx.write_file('.coverage.xxx')
        covdata_xxx.write_file('cov2/.coverage.xxx')

        covdata3 = CoverageData()
        self.data_files.combine_parallel_data(covdata3, data_paths=['cov1', 'cov2/.coverage.2'])

        self.assert_line_counts(covdata3, SUMMARY_1_2)
        self.assert_measured_files(covdata3, MEASURED_FILES_1_2)
        self.assert_doesnt_exist("cov1/.coverage.1")
        self.assert_doesnt_exist("cov2/.coverage.2")
        self.assert_exists(".coverage.xxx")
        self.assert_exists("cov2/.coverage.xxx")
Пример #2
0
    def test_read_write_arcs(self):
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)
        covdata1.write_file("arcs.dat")

        covdata2 = CoverageData()
        covdata2.read_file("arcs.dat")
        self.assert_arcs3_data(covdata2)
Пример #3
0
 def test_no_arcs_vs_unmeasured_file(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.touch_file('zzz.py')
     self.assertEqual(covdata.lines('zzz.py'), [])
     self.assertIsNone(covdata.lines('no_such_file.py'))
     self.assertEqual(covdata.arcs('zzz.py'), [])
     self.assertIsNone(covdata.arcs('no_such_file.py'))
Пример #4
0
 def test_no_arcs_vs_unmeasured_file(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.touch_file('zzz.py')
     self.assertEqual(covdata.lines('zzz.py'), [])
     self.assertIsNone(covdata.lines('no_such_file.py'))
     self.assertEqual(covdata.arcs('zzz.py'), [])
     self.assertIsNone(covdata.arcs('no_such_file.py'))
Пример #5
0
 def test_adding_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     self.assert_line_counts(covdata, SUMMARY_3)
     self.assert_measured_files(covdata, MEASURED_FILES_3)
     self.assertCountEqual(covdata.lines("x.py"), X_PY_LINES_3)
     self.assertCountEqual(covdata.arcs("x.py"), X_PY_ARCS_3)
     self.assertCountEqual(covdata.lines("y.py"), Y_PY_LINES_3)
     self.assertCountEqual(covdata.arcs("y.py"), Y_PY_ARCS_3)
     self.assertTrue(covdata.has_arcs())
Пример #6
0
 def test_add_to_hash_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.set_file_tracers({"y.py": "hologram_plugin"})
     hasher = mock.Mock()
     covdata.add_to_hash("y.py", hasher)
     self.assertEqual(hasher.method_calls, [
         mock.call.update([(-1, 17), (17, 23), (23, -1)]),   # arcs
         mock.call.update("hologram_plugin"),                # file_tracer name
     ])
Пример #7
0
 def test_add_to_hash_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.set_file_tracers({"y.py": "hologram_plugin"})
     hasher = mock.Mock()
     covdata.add_to_hash("y.py", hasher)
     self.assertEqual(hasher.method_calls, [
         mock.call.update([(-1, 17), (17, 23), (23, -1)]),   # arcs
         mock.call.update("hologram_plugin"),                # file_tracer name
     ])
Пример #8
0
    def test_read_write_arcs_pickle(self):
        # Test the old pickle format.
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)
        self.write_pickled_file(covdata1, "arcs.pkl")

        pickle2json("arcs.pkl", "arcs.json")

        covdata2 = CoverageData()
        covdata2.read_file("arcs.json")
        self.assert_arcs3_data(covdata2)
Пример #9
0
    def test_read_write_arcs_pickle(self):
        # Test the old pickle format.
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)
        self.write_pickled_file(covdata1, "arcs.pkl")

        pickle2json("arcs.pkl", "arcs.json")

        covdata2 = CoverageData()
        covdata2.read_file("arcs.json")
        self.assert_arcs3_data(covdata2)
Пример #10
0
    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()
        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)
Пример #12
0
    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(), [])
Пример #13
0
    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(), [])
Пример #14
0
    def test_read_write_arcs(self):
        covdata1 = CoverageData()
        covdata1.set_arcs(ARCS_3)
        covdata1.write_file("arcs.dat")

        covdata2 = CoverageData()
        covdata2.read_file("arcs.dat")
        self.assert_line_counts(covdata2, SUMMARY_3)
        self.assert_measured_files(covdata2, MEASURED_FILES_3)
        self.assertCountEqual(covdata2.lines("x.py"), X_PY_LINES_3)
        self.assertCountEqual(covdata2.arcs("x.py"), X_PY_ARCS_3)
        self.assertCountEqual(covdata2.lines("y.py"), Y_PY_LINES_3)
        self.assertCountEqual(covdata2.arcs("y.py"), Y_PY_ARCS_3)
        self.assertEqual(covdata2.run_infos(), [])
Пример #15
0
    def test_file_format_with_arcs(self):
        # Write with CoverageData, then read the JSON explicitly.
        covdata = CoverageData()
        covdata.set_arcs(ARCS_3)
        self.data_files.write(covdata)

        data = self.read_json_data_file(".coverage")

        self.assertNotIn('lines', data)
        arcs = data['arcs']
        self.assertCountEqual(arcs.keys(), MEASURED_FILES_3)
        self.assertCountEqual(arcs['x.py'], map(list, X_PY_ARCS_3))
        self.assertCountEqual(arcs['y.py'], map(list, Y_PY_ARCS_3))
        # If no file tracers were involved, there's no file_tracers entry.
        self.assertNotIn('file_tracers', data)
Пример #16
0
    def test_file_format_with_arcs(self):
        # Write with CoverageData, then read the JSON explicitly.
        covdata = CoverageData()
        covdata.set_arcs(ARCS_3)
        self.data_files.write(covdata)

        data = self.read_json_data_file(".coverage")

        self.assertNotIn('lines', data)
        arcs = data['arcs']
        self.assertCountEqual(arcs.keys(), MEASURED_FILES_3)
        self.assertCountEqual(arcs['x.py'], map(list, X_PY_ARCS_3))
        self.assertCountEqual(arcs['y.py'], map(list, Y_PY_ARCS_3))
        # If no file tracers were involved, there's no file_tracers entry.
        self.assertNotIn('file_tracers', data)
Пример #17
0
    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},
        ])
Пример #18
0
    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},
        ])
Пример #19
0
    def test_debug_main(self):
        covdata1 = CoverageData()
        covdata1.set_lines(LINES_1)
        covdata1.write_file(".coverage")
        debug_main([])

        covdata2 = CoverageData()
        covdata2.set_arcs(ARCS_3)
        covdata2.set_file_tracers({"y.py": "magic_plugin"})
        covdata2.add_run_info(version="v3.14", chunks=["z", "a"])
        covdata2.write_file("arcs.dat")

        covdata3 = CoverageData()
        covdata3.write_file("empty.dat")
        debug_main(["arcs.dat", "empty.dat"])

        expected = {
            ".coverage": {
                "lines": {
                    "a.py": [1, 2],
                    "b.py": [3],
                },
            },
            "arcs.dat": {
                "arcs": {
                    "x.py": [[-1, 1], [1, 2], [2, 3], [3, -1]],
                    "y.py": [[-1, 17], [17, 23], [23, -1]],
                },
                "file_tracers": {"y.py": "magic_plugin"},
                "runs": [
                    {
                        "chunks": ["z", "a"],
                        "version": "v3.14",
                    },
                ],
            },
            "empty.dat": {"lines": {}},
        }
        pieces = re.split(r"(?m)-+ ([\w.]+) -+$", self.stdout())
        for name, json_out in zip(pieces[1::2], pieces[2::2]):
            json_got = json.loads(json_out)
            canonicalize_json_data(json_got)
            self.assertEqual(expected[name], json_got)
Пример #20
0
    def test_debug_main(self):
        covdata1 = CoverageData()
        covdata1.set_lines(LINES_1)
        covdata1.write_file(".coverage")
        debug_main([])

        covdata2 = CoverageData()
        covdata2.set_arcs(ARCS_3)
        covdata2.set_file_tracers({"y.py": "magic_plugin"})
        covdata2.add_run_info(version="v3.14", chunks=["z", "a"])
        covdata2.write_file("arcs.dat")

        covdata3 = CoverageData()
        covdata3.write_file("empty.dat")
        debug_main(["arcs.dat", "empty.dat"])

        expected = {
            ".coverage": {
                "lines": {
                    "a.py": [1, 2],
                    "b.py": [3],
                },
            },
            "arcs.dat": {
                "arcs": {
                    "x.py": [[-1, 1], [1, 2], [2, 3], [3, -1]],
                    "y.py": [[-1, 17], [17, 23], [23, -1]],
                },
                "file_tracers": {"y.py": "magic_plugin"},
                "runs": [
                    {
                        "chunks": ["z", "a"],
                        "version": "v3.14",
                    },
                ],
            },
            "empty.dat": {"lines": {}},
        }
        pieces = re.split(r"(?m)-+ ([\w.]+) -+$", self.stdout())
        for name, json_out in zip(pieces[1::2], pieces[2::2]):
            json_got = json.loads(json_out)
            canonicalize_json_data(json_got)
            self.assertEqual(expected[name], json_got)
Пример #21
0
 def test_arc_data_is_true(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     self.assertTrue(covdata)
Пример #22
0
 def test_arc_data_is_true(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     self.assertTrue(covdata)
Пример #23
0
 def test_adding_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     self.assert_arcs3_data(covdata)
Пример #24
0
 def test_cant_set_lines_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     with self.assertRaisesRegex(CoverageException, "Can't add lines to existing arc data"):
         covdata.set_lines(LINES_1)
Пример #25
0
 def test_touch_file_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.touch_file('zzz.py')
     self.assert_measured_files(covdata, MEASURED_FILES_3 + ['zzz.py'])
Пример #26
0
 def test_touch_file_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     covdata.touch_file('zzz.py')
     self.assert_measured_files(covdata, MEASURED_FILES_3 + ['zzz.py'])
Пример #27
0
 def test_cant_set_lines_with_arcs(self):
     covdata = CoverageData()
     covdata.set_arcs(ARCS_3)
     with self.assertRaisesRegex(CoverageException, "Can't add lines to existing arc data"):
         covdata.set_lines(LINES_1)