Skip to content

Commit

Permalink
Fix doctesting with Python 3.13
Browse files Browse the repository at this point in the history
Adapt to upstream changes in doctest [1]:

- _name2ft was renamed to _stats
- it now records the number of skipped tests

[1] python/cpython@4f9b706
  • Loading branch information
antonio-rojas committed Dec 16, 2024
1 parent e7477f8 commit 63965d4
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ def __init__(self, *args, **kwds):
self.total_walltime_skips = 0
self.total_performed_tests = 0
self.total_walltime = 0
if not hasattr(self, "_stats"):
self._stats = self._name2ft

def _run(self, test, compileflags, out):
"""
Expand Down Expand Up @@ -830,7 +832,10 @@ def compiler(example):
self.optionflags = original_optionflags

# Record and return the number of failures and tries.
self._DocTestRunner__record_outcome(test, failures, tries)
try:
self._DocTestRunner__record_outcome(test, failures, tries, walltime_skips)
except TypeError:
self._DocTestRunner__record_outcome(test, failures, tries)
self.total_walltime_skips += walltime_skips
self.total_performed_tests += tries
return TestResults(failures, tries)
Expand Down Expand Up @@ -931,7 +936,7 @@ def summarize(self, verbose=None):
sage: from sage.doctest.control import DocTestDefaults; DD = DocTestDefaults()
sage: import doctest, sys, os
sage: DTR = SageDocTestRunner(SageOutputChecker(), verbose=False, sage_options=DD, optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS)
sage: DTR._name2ft['sage.doctest.forker'] = (1,120)
sage: DTR._stats['sage.doctest.forker'] = (1,120)
sage: results = DTR.summarize()
**********************************************************************
1 item had failures:
Expand All @@ -946,15 +951,15 @@ def summarize(self, verbose=None):
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
assert f <= t
totalt += t
totalf += f
if not t:
for x in self._stats.items():
name, f = x
assert f[0] <= f[1]
totalt += f[1]
totalf += f[0]
if not f[1]:
notests.append(name)
elif not f:
passed.append((name, t))
elif not f[0]:
passed.append((name, f[1]))
else:
failed.append(x)
if verbose:
Expand All @@ -972,10 +977,10 @@ def summarize(self, verbose=None):
print(self.DIVIDER, file=m)
print(count_noun(len(failed), "item"), "had failures:", file=m)
failed.sort()
for thing, (f, t) in failed:
print(" %3d of %3d in %s" % (f, t, thing), file=m)
for thing, f in failed:
print(" %3d of %3d in %s" % (f[0], f[1], thing), file=m)
if verbose:
print(count_noun(totalt, "test") + " in " + count_noun(len(self._name2ft), "item") + ".", file=m)
print(count_noun(totalt, "test") + " in " + count_noun(len(self._stats), "item") + ".", file=m)
print("%s passed and %s failed." % (totalt - totalf, totalf), file=m)
if totalf:
print("***Test Failed***", file=m)
Expand Down

0 comments on commit 63965d4

Please sign in to comment.