]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-51524: Fix bug when calling trace.CoverageResults with valid infile (#99629)
authorFurkan Onder <furkanonder@protonmail.com>
Mon, 28 Nov 2022 06:49:10 +0000 (09:49 +0300)
committerGitHub <noreply@github.com>
Mon, 28 Nov 2022 06:49:10 +0000 (01:49 -0500)
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Lib/test/test_trace.py
Lib/trace.py
Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst [new file with mode: 0644]

index 5f712111ca14e05897ddbf40210ba35a2bf9fcf8..fad2b3b8379ffc8831a8cad71e818b8f354740e9 100644 (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 @@ class TestCoverage(unittest.TestCase):
         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.
index 2cf3643878d4b8d57aba74d7fffa49a12f1ffc38..213e46517d683d7e132936a042ec95cf1b465cb9 100755 (executable)
@@ -172,7 +172,7 @@ class CoverageResults:
             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)
diff --git a/Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst b/Misc/NEWS.d/next/Library/2022-11-21-17-56-18.gh-issue-51524.nTykx8.rst
new file mode 100644 (file)
index 0000000..63fe7b8
--- /dev/null
@@ -0,0 +1 @@
+Fix bug when calling trace.CoverageResults with valid infile.