Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-51524: Fix bug when calling trace.CoverageResults with valid infile #99629

Merged
merged 7 commits into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Lib/test/test_trace.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Lib/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug when calling trace.CoverageResults with valid infile.