Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55e1064

Browse filesBrowse files
CPython Developersyouknowone
CPython Developers
authored andcommitted
Update trace from CPython 3.11.2
1 parent 351d464 commit 55e1064
Copy full SHA for 55e1064

File tree

2 files changed

+30
-31
lines changed
Filter options

2 files changed

+30
-31
lines changed

‎Lib/test/test_trace.py

Copy file name to clipboardExpand all lines: Lib/test/test_trace.py
+27-12Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import os
2+
from pickle import dump
23
import sys
34
from test.support import captured_stdout
4-
from test.support.os_helper import TESTFN, TESTFN_UNICODE, FS_NONASCII, rmtree, unlink
5+
from test.support.os_helper import (TESTFN, rmtree, unlink)
56
from test.support.script_helper import assert_python_ok, assert_python_failure
67
import textwrap
78
import unittest
@@ -11,6 +12,11 @@
1112

1213
from test.tracedmodules import testmod
1314

15+
##
16+
## See also test_sys_settrace.py, which contains tests that cover
17+
## tracing of many more code blocks.
18+
##
19+
1420
#------------------------------- Utilities -----------------------------------#
1521

1622
def fix_ext_py(filename):
@@ -191,7 +197,7 @@ def test_trace_list_comprehension(self):
191197
firstlineno_called = get_firstlineno(traced_doubler)
192198
expected = {
193199
(self.my_py_filename, firstlineno_calling + 1): 1,
194-
# List compehentions work differently in 3.x, so the count
200+
# List comprehensions work differently in 3.x, so the count
195201
# below changed compared to 2.x.
196202
(self.my_py_filename, firstlineno_calling + 2): 12,
197203
(self.my_py_filename, firstlineno_calling + 3): 1,
@@ -212,9 +218,9 @@ def test_traced_decorated_function(self):
212218
(self.my_py_filename, firstlineno + 4): 1,
213219
(self.my_py_filename, firstlineno + 5): 1,
214220
(self.my_py_filename, firstlineno + 6): 1,
215-
(self.my_py_filename, firstlineno + 7): 1,
216-
(self.my_py_filename, firstlineno + 8): 1,
217-
(self.my_py_filename, firstlineno + 9): 1,
221+
(self.my_py_filename, firstlineno + 7): 2,
222+
(self.my_py_filename, firstlineno + 8): 2,
223+
(self.my_py_filename, firstlineno + 9): 2,
218224
(self.my_py_filename, firstlineno + 10): 1,
219225
(self.my_py_filename, firstlineno + 11): 1,
220226
}
@@ -297,9 +303,8 @@ def test_simple_caller(self):
297303
def test_arg_errors(self):
298304
res = self.tracer.runfunc(traced_capturer, 1, 2, self=3, func=4)
299305
self.assertEqual(res, ((1, 2), {'self': 3, 'func': 4}))
300-
with self.assertWarns(DeprecationWarning):
301-
res = self.tracer.runfunc(func=traced_capturer, arg=1)
302-
self.assertEqual(res, ((), {'arg': 1}))
306+
with self.assertRaises(TypeError):
307+
self.tracer.runfunc(func=traced_capturer, arg=1)
303308
with self.assertRaises(TypeError):
304309
self.tracer.runfunc()
305310

@@ -356,7 +361,6 @@ def setUp(self):
356361

357362
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
358363
'pre-existing trace function throws off measurements')
359-
@unittest.skip("TODO: RUSTPYTHON, Error in atexit._run_exitfuncs")
360364
def test_loop_caller_importing(self):
361365
self.tracer.runfunc(traced_func_importing_caller, 1)
362366

@@ -406,7 +410,7 @@ def test_coverage(self):
406410

407411
def test_coverage_ignore(self):
408412
# Ignore all files, nothing should be traced nor printed
409-
libpath = os.path.normpath(os.path.dirname(os.__file__))
413+
libpath = os.path.normpath(os.path.dirname(os.path.dirname(__file__)))
410414
# sys.prefix does not work when running from a checkout
411415
tracer = trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,
412416
libpath], trace=0, count=1)
@@ -439,6 +443,15 @@ def test_issue9936(self):
439443
self.assertIn(modname, coverage)
440444
self.assertEqual(coverage[modname], (5, 100))
441445

446+
def test_coverageresults_update(self):
447+
# Update empty CoverageResults with a non-empty infile.
448+
infile = TESTFN + '-infile'
449+
with open(infile, 'wb') as f:
450+
dump(({}, {}, {'caller': 1}), f, protocol=1)
451+
self.addCleanup(unlink, infile)
452+
results = trace.CoverageResults({}, {}, infile, {})
453+
self.assertEqual(results.callers, {'caller': 1})
454+
442455
### Tests that don't mess with sys.settrace and can be traced
443456
### themselves TODO: Skip tests that do mess with sys.settrace when
444457
### regrtest is invoked with -T option.
@@ -547,7 +560,8 @@ def test_sys_argv_list(self):
547560
fd.write("print(type(sys.argv))\n")
548561

549562
status, direct_stdout, stderr = assert_python_ok(TESTFN)
550-
status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN)
563+
status, trace_stdout, stderr = assert_python_ok('-m', 'trace', '-l', TESTFN,
564+
PYTHONIOENCODING='utf-8')
551565
self.assertIn(direct_stdout.strip(), trace_stdout)
552566

553567
# TODO: RUSTPYTHON
@@ -569,7 +583,8 @@ def f():
569583
for i in range(10):
570584
f()
571585
"""))
572-
status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename)
586+
status, stdout, _ = assert_python_ok('-m', 'trace', '-cs', filename,
587+
PYTHONIOENCODING='utf-8')
573588
stdout = stdout.decode()
574589
self.assertEqual(status, 0)
575590
self.assertIn('lines cov% module (path)', stdout)

‎Lib/trace.py

Copy file name to clipboard
100644100755
Expand all lines: Lib/trace.py
+3-19Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def names(self, filename, modulename):
116116
return 0
117117

118118
def _modname(path):
119-
"""Return a plausible module name for the patch."""
119+
"""Return a plausible module name for the path."""
120120

121121
base = os.path.basename(path)
122122
filename, ext = os.path.splitext(base)
@@ -172,7 +172,7 @@ def __init__(self, counts=None, calledfuncs=None, infile=None,
172172
try:
173173
with open(self.infile, 'rb') as f:
174174
counts, calledfuncs, callers = pickle.load(f)
175-
self.update(self.__class__(counts, calledfuncs, callers))
175+
self.update(self.__class__(counts, calledfuncs, callers=callers))
176176
except (OSError, EOFError, ValueError) as err:
177177
print(("Skipping counts file %r: %s"
178178
% (self.infile, err)), file=sys.stderr)
@@ -453,22 +453,7 @@ def runctx(self, cmd, globals=None, locals=None):
453453
sys.settrace(None)
454454
threading.settrace(None)
455455

456-
def runfunc(*args, **kw):
457-
if len(args) >= 2:
458-
self, func, *args = args
459-
elif not args:
460-
raise TypeError("descriptor 'runfunc' of 'Trace' object "
461-
"needs an argument")
462-
elif 'func' in kw:
463-
func = kw.pop('func')
464-
self, *args = args
465-
import warnings
466-
warnings.warn("Passing 'func' as keyword argument is deprecated",
467-
DeprecationWarning, stacklevel=2)
468-
else:
469-
raise TypeError('runfunc expected at least 1 positional argument, '
470-
'got %d' % (len(args)-1))
471-
456+
def runfunc(self, func, /, *args, **kw):
472457
result = None
473458
if not self.donothing:
474459
sys.settrace(self.globaltrace)
@@ -478,7 +463,6 @@ def runfunc(*args, **kw):
478463
if not self.donothing:
479464
sys.settrace(None)
480465
return result
481-
runfunc.__text_signature__ = '($self, func, /, *args, **kw)'
482466

483467
def file_module_function_of(self, frame):
484468
code = frame.f_code

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.