OLD | NEW |
(Empty) | |
| 1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
| 2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
| 3 |
| 4 """Tests for coverage.pickle2json""" |
| 5 |
| 6 from coverage.backward import pickle, iitems |
| 7 from coverage.data import CoverageData |
| 8 from coverage.pickle2json import pickle2json |
| 9 |
| 10 from tests.coveragetest import CoverageTest |
| 11 from tests.test_data import DataTestHelpers, LINES_1, ARCS_3 |
| 12 |
| 13 |
| 14 class Pickle2JsonTestInTempDir(DataTestHelpers, CoverageTest): |
| 15 """Tests pickle2json.py.""" |
| 16 |
| 17 no_files_in_temp_dir = True |
| 18 |
| 19 def write_pickled_file(self, covdata, filename): |
| 20 """Write coverage data as pickled `filename`.""" |
| 21 # Create the file data. |
| 22 file_data = {} |
| 23 |
| 24 if covdata._arcs: |
| 25 file_data['arcs'] = dict((f, list(amap)) for f, amap in iitems(covda
ta._arcs)) |
| 26 else: |
| 27 file_data['lines'] = dict((f, list(lmap)) for f, lmap in iitems(covd
ata._lines)) |
| 28 |
| 29 # Write the pickle to the file. |
| 30 with open(filename, 'wb') as file_obj: |
| 31 pickle.dump(file_data, file_obj, 2) |
| 32 |
| 33 def test_read_write_lines_pickle(self): |
| 34 # Test the old pickle format. |
| 35 covdata1 = CoverageData() |
| 36 covdata1.add_lines(LINES_1) |
| 37 self.write_pickled_file(covdata1, "lines.pkl") |
| 38 |
| 39 pickle2json("lines.pkl", "lines.json") |
| 40 |
| 41 covdata2 = CoverageData() |
| 42 covdata2.read_file("lines.json") |
| 43 self.assert_lines1_data(covdata2) |
| 44 |
| 45 def test_read_write_arcs_pickle(self): |
| 46 # Test the old pickle format. |
| 47 covdata1 = CoverageData() |
| 48 covdata1.add_arcs(ARCS_3) |
| 49 self.write_pickled_file(covdata1, "arcs.pkl") |
| 50 |
| 51 pickle2json("arcs.pkl", "arcs.json") |
| 52 |
| 53 covdata2 = CoverageData() |
| 54 covdata2.read_file("arcs.json") |
| 55 self.assert_arcs3_data(covdata2) |
OLD | NEW |