gh-51524: Fix bug when calling trace.CoverageResults with valid infile (GH-99629)

(cherry picked from commit 594de165bf)

Co-authored-by: Furkan Onder <furkanonder@protonmail.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
Miss Islington (bot) 2022-11-27 23:15:00 -08:00 committed by GitHub
parent f160996412
commit fce9516a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import os
from pickle import dump
import sys
from test.support import captured_stdout
from test.support.os_helper import (TESTFN, rmtree, unlink)
@ -412,6 +413,15 @@ def test_issue9936(self):
self.assertIn(modname, coverage)
self.assertEqual(coverage[modname], (5, 100))
def test_coverageresults_update(self):
# Update empty CoverageResults with a non-empty infile.
infile = TESTFN + '-infile'
with open(infile, 'wb') as f:
dump(({}, {}, {'caller': 1}), f, protocol=1)
self.addCleanup(unlink, infile)
results = trace.CoverageResults({}, {}, infile, {})
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.

View File

@ -172,7 +172,7 @@ def __init__(self, counts=None, calledfuncs=None, infile=None,
try:
with open(self.infile, 'rb') as f:
counts, calledfuncs, callers = pickle.load(f)
self.update(self.__class__(counts, calledfuncs, callers))
self.update(self.__class__(counts, calledfuncs, callers=callers))
except (OSError, EOFError, ValueError) as err:
print(("Skipping counts file %r: %s"
% (self.infile, err)), file=sys.stderr)

View File

@ -0,0 +1 @@
Fix bug when calling trace.CoverageResults with valid infile.