diff options
author | Alexander Todorov <atodorov@otb.bg> | 2015-08-07 16:50:51 +0300 |
---|---|---|
committer | Alexander Todorov <atodorov@otb.bg> | 2015-08-07 16:50:51 +0300 |
commit | 5ffeef081a9efca75c7557b244660d3226467350 (patch) | |
tree | c42e1f0e0becda74382a66d9ded7c299160ccc10 /tests | |
parent | 4111d81a2bfc41d7ce9f2426cfe4cd4d137d6e8e (diff) | |
download | python-coveragepy-git-5ffeef081a9efca75c7557b244660d3226467350.tar.gz |
Add pickle2json converter. Closes #395
--HG--
branch : read_pickle
extra : amend_source : 71ae428d9f389e19ed74215bfc3f1630fcdc40a1
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pickle2json.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_pickle2json.py b/tests/test_pickle2json.py new file mode 100644 index 00000000..06dc4c2e --- /dev/null +++ b/tests/test_pickle2json.py @@ -0,0 +1,64 @@ +# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 +# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt + +"""Tests for coverage.pickle2json""" + +from coverage.backward import pickle, iitems +from coverage.data import CoverageData +from coverage.pickle2json import pickle2json + +from tests.coveragetest import CoverageTest +from tests.test_data import * + +class Pickle2JsonTestInTempDir(DataTestHelpers, CoverageTest): + """ Tests pickle2json """ + + def write_pickled_file(self, covdata, filename): + """ write coverage data as pickled `filename` """ + # Create the file data. + file_data = {} + + if covdata._arcs: + file_data['arcs'] = dict((f, list(amap)) for f, amap in iitems(covdata._arcs)) + else: + file_data['lines'] = dict((f, list(lmap)) for f, lmap in iitems(covdata._lines)) + + # Write the pickle to the file. + file_obj = open(filename, 'wb') + try: + pickle.dump(file_data, file_obj, 2) + finally: + file_obj.close() + + def test_read_write_lines_pickle(self): + """ test the old pickle format """ + covdata1 = CoverageData() + covdata1.set_lines(LINES_1) + self.write_pickled_file(covdata1, "lines.pkl") + + pickle2json("lines.pkl", "lines.json") + + covdata2 = CoverageData() + covdata2.read_file("lines.json") + self.assert_line_counts(covdata2, SUMMARY_1) + self.assert_measured_files(covdata2, MEASURED_FILES_1) + self.assertCountEqual(covdata2.lines("a.py"), A_PY_LINES_1) + self.assertEqual(covdata2.run_infos(), []) + + 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_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(), []) |