diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py --- a/Lib/test/test_trace.py +++ b/Lib/test/test_trace.py @@ -1,9 +1,10 @@ import os +import pickle import sys from test.support import TESTFN, rmtree, unlink, captured_stdout from test.support.script_helper import assert_python_ok, assert_python_failure import unittest import trace from trace import Trace @@ -345,16 +346,24 @@ class TestCoverage(unittest.TestCase): for line in stdout: lines, cov, module = line.split()[:3] coverage[module] = (int(lines), int(cov[:-1])) # XXX This is needed to run regrtest.py as a script modname = trace._fullmodname(sys.modules[modname].__file__) self.assertIn(modname, coverage) self.assertEqual(coverage[modname], (5, 100)) + def test_coverageresults_update(self): + outfile = TESTFN + '-outfile' + with open(outfile, 'wb') as f: + pickle.dump(({}, {}, {'caller': 1}), f, protocol=1) + self.addCleanup(unlink, outfile) + results = trace.CoverageResults({}, {}, outfile, {}) + self.assertEqual(results.callers, {'caller': 1}) + ### Tests that don't mess with sys.settrace and can be traced ### themselves TODO: Skip tests that do mess with sys.settrace when ### regrtest is invoked with -T option. class Test_Ignore(unittest.TestCase): def test_ignored(self): jn = os.path.join ignore = trace._Ignore(['x', 'y.z'], [jn('foo', 'bar')]) self.assertTrue(ignore.names('x.py', 'x')) diff --git a/Lib/trace.py b/Lib/trace.py --- a/Lib/trace.py +++ b/Lib/trace.py @@ -179,22 +179,22 @@ class CoverageResults: self.calledfuncs = {} self.calledfuncs = self.calledfuncs.copy() self.callers = callers if self.callers is None: self.callers = {} self.callers = self.callers.copy() self.infile = infile self.outfile = outfile - if self.infile: + if self.infile is not None: # Try to merge existing counts file. try: with open(self.infile, 'rb') as f: counts, calledfuncs, callers = pickle.load(f) - self.update(self.__class__(counts, calledfuncs, callers)) + self.update(CoverageResults(counts, calledfuncs, callers=callers)) except (OSError, EOFError, ValueError) as err: print(("Skipping counts file %r: %s" % (self.infile, err)), file=sys.stderr) def is_ignored_filename(self, filename): """Return True if the filename does not refer to a file we want to have reported. """