Skip to content

Commit bc108df

Browse files
authored
Update trace.py from 3.14.3 (#7327)
* Update `trace.py` from 3.14.3 * Mark failing tests
1 parent 1d106c3 commit bc108df

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

Lib/test/test_trace.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from pickle import dump
33
import sys
4-
from test.support import captured_stdout, requires_resource, requires_gil_enabled
4+
from test.support import captured_stdout, requires_resource
55
from test.support.os_helper import (TESTFN, rmtree, unlink)
66
from test.support.script_helper import assert_python_ok, assert_python_failure
77
import textwrap
@@ -307,9 +307,9 @@ def test_loop_caller_importing(self):
307307
}
308308
self.assertEqual(self.tracer.results().calledfuncs, expected)
309309

310+
@unittest.expectedFailure # TODO: RUSTPYTHON
310311
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
311312
'pre-existing trace function throws off measurements')
312-
@requires_gil_enabled("gh-117783: immortalization of types affects traced method names")
313313
def test_inst_method_calling(self):
314314
obj = TracedClass(20)
315315
self.tracer.runfunc(obj.inst_method_calling, 1)
@@ -341,9 +341,9 @@ def setUp(self):
341341
self.tracer = Trace(count=0, trace=0, countcallers=1)
342342
self.filemod = my_file_and_modname()
343343

344+
@unittest.expectedFailure # TODO: RUSTPYTHON
344345
@unittest.skipIf(hasattr(sys, 'gettrace') and sys.gettrace(),
345346
'pre-existing trace function throws off measurements')
346-
@requires_gil_enabled("gh-117783: immortalization of types affects traced method names")
347347
def test_loop_caller_importing(self):
348348
self.tracer.runfunc(traced_func_importing_caller, 1)
349349

@@ -424,7 +424,7 @@ def test_issue9936(self):
424424
coverage = {}
425425
for line in stdout:
426426
lines, cov, module = line.split()[:3]
427-
coverage[module] = (int(lines), int(cov[:-1]))
427+
coverage[module] = (float(lines), float(cov[:-1]))
428428
# XXX This is needed to run regrtest.py as a script
429429
modname = trace._fullmodname(sys.modules[modname].__file__)
430430
self.assertIn(modname, coverage)
@@ -568,7 +568,7 @@ def f():
568568
stdout = stdout.decode()
569569
self.assertEqual(status, 0)
570570
self.assertIn('lines cov% module (path)', stdout)
571-
self.assertIn(f'6 100% {modulename} ({filename})', stdout)
571+
self.assertIn(f'6 100.0% {modulename} ({filename})', stdout)
572572

573573
def test_run_as_module(self):
574574
assert_python_ok('-m', 'trace', '-l', '--module', 'timeit', '-n', '1')

Lib/trace.py

100755100644
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env python3
2-
31
# portions copyright 2001, Autonomous Zones Industries, Inc., all rights...
42
# err... reserved and offered to the public under the terms of the
53
# Python 2.2 license.
@@ -281,14 +279,13 @@ def write_results(self, show_missing=True, summary=False, coverdir=None, *,
281279
n_hits, n_lines = self.write_results_file(coverpath, source,
282280
lnotab, count, encoding)
283281
if summary and n_lines:
284-
percent = int(100 * n_hits / n_lines)
285-
sums[modulename] = n_lines, percent, modulename, filename
282+
sums[modulename] = n_lines, n_hits, modulename, filename
286283

287284
if summary and sums:
288285
print("lines cov% module (path)")
289286
for m in sorted(sums):
290-
n_lines, percent, modulename, filename = sums[m]
291-
print("%5d %3d%% %s (%s)" % sums[m])
287+
n_lines, n_hits, modulename, filename = sums[m]
288+
print(f"{n_lines:5d} {n_hits/n_lines:.1%} {modulename} ({filename})")
292289

293290
if self.outfile:
294291
# try and store counts and module info into self.outfile
@@ -402,7 +399,7 @@ def __init__(self, count=1, trace=1, countfuncs=0, countcallers=0,
402399
@param countfuncs true iff it should just output a list of
403400
(filename, modulename, funcname,) for functions
404401
that were called at least once; This overrides
405-
`count' and `trace'
402+
'count' and 'trace'
406403
@param ignoremods a list of the names of modules to ignore
407404
@param ignoredirs a list of the names of directories to ignore
408405
all of the (recursive) contents of
@@ -534,7 +531,7 @@ def globaltrace_countfuncs(self, frame, why, arg):
534531
def globaltrace_lt(self, frame, why, arg):
535532
"""Handler for call events.
536533
537-
If the code block being entered is to be ignored, returns `None',
534+
If the code block being entered is to be ignored, returns 'None',
538535
else returns self.localtrace.
539536
"""
540537
if why == 'call':
@@ -607,7 +604,7 @@ def results(self):
607604
def main():
608605
import argparse
609606

610-
parser = argparse.ArgumentParser()
607+
parser = argparse.ArgumentParser(color=True)
611608
parser.add_argument('--version', action='version', version='trace 2.0')
612609

613610
grp = parser.add_argument_group('Main options',

0 commit comments

Comments
 (0)