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")
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)
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'))
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())
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 ])
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)
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)
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(), [])
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(), [])
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)
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}, ])
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)
def test_arc_data_is_true(self): covdata = CoverageData() covdata.set_arcs(ARCS_3) self.assertTrue(covdata)
def test_adding_arcs(self): covdata = CoverageData() covdata.set_arcs(ARCS_3) self.assert_arcs3_data(covdata)
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)
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'])