diff options
-rw-r--r-- | coverage/data.py | 16 | ||||
-rw-r--r-- | tests/test_data.py | 23 | ||||
-rw-r--r-- | tox.ini | 2 |
3 files changed, 37 insertions, 4 deletions
diff --git a/coverage/data.py b/coverage/data.py index f2e528d4..e5c37cb7 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -267,9 +267,19 @@ class CoverageData(object): return list(self._arcs or self._lines) def add_to_hash(self, filename, hasher): - """Contribute `filename`'s data to the Md5Hash `hasher`.""" - hasher.update(self.lines(filename)) - hasher.update(self.arcs(filename)) + """Contribute `filename`'s data to the `hasher`. + + Arguments: + filename (str): the filename we're interested in. + hasher (:class:`coverage.misc.Hasher`): the Hasher to update with + the file's data. + + """ + if self._arcs: + hasher.update(sorted(self.arcs(filename))) + else: + hasher.update(sorted(self.lines(filename))) + hasher.update(self.plugin_name(filename)) def line_counts(self, fullpath=False): """Return a dict summarizing the line coverage data. diff --git a/tests/test_data.py b/tests/test_data.py index d43e0308..c654c8fc 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -4,6 +4,8 @@ import glob import os import os.path +import mock + from coverage.backward import pickle from coverage.data import CoverageData, CoverageDataFiles from coverage.files import PathAliases, canonical_filename @@ -263,6 +265,27 @@ class CoverageDataTest(DataTestHelpers, CoverageTest): with self.assertRaises(CoverageException): covdata2.update(covdata1) + def test_add_to_hash_with_lines(self): + covdata = CoverageData() + covdata.add_lines(LINES_1) + hasher = mock.Mock() + covdata.add_to_hash("a.py", hasher) + self.assertEqual(hasher.method_calls, [ + mock.call.update([1, 2]), # lines + mock.call.update(""), # plugin name + ]) + + def test_add_to_hash_with_arcs(self): + covdata = CoverageData() + covdata.add_arcs(ARCS_3) + covdata.add_plugins({"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"), # plugin name + ]) + class CoverageDataTestInTempDir(DataTestHelpers, CoverageTest): """Tests of CoverageData that need a temp dir to make files.""" @@ -25,7 +25,7 @@ commands = deps = nose - mock==1.0.1 + mock PyContracts py26: unittest2 py26,py27: gevent |