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

Fix doctesting with Python 3.13 #39147

Merged
merged 3 commits into from
Jan 18, 2025
Merged
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
17 changes: 11 additions & 6 deletions src/sage/doctest/forker.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@
self.total_walltime_skips = 0
self.total_performed_tests = 0
self.total_walltime = 0
if sys.version_info < (3,13):
self._stats = self._name2ft

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

# Record and return the number of failures and tries.
self._DocTestRunner__record_outcome(test, failures, tries)
if sys.version_info < (3,13):
self._DocTestRunner__record_outcome(test, failures, tries)
else:
self._DocTestRunner__record_outcome(test, failures, tries, walltime_skips)

Check warning on line 838 in src/sage/doctest/forker.py

View check run for this annotation

Codecov / codecov/patch

src/sage/doctest/forker.py#L838

Added line #L838 was not covered by tests
self.total_walltime_skips += walltime_skips
self.total_performed_tests += tries
return TestResults(failures, tries)
Expand Down Expand Up @@ -931,7 +936,7 @@
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)
Copy link
Contributor

@tornaria tornaria Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: DTR._stats['sage.doctest.forker'] = (1,120)
sage: DTR._stats['sage.doctest.forker'] = (1,120,0)

It seems the difference between _name2ft and _stats is the former is pairs but the latter is triples.

Copy link
Contributor

@user202729 user202729 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the point.

I think the doctest can be left as is because it's just mocking the result here… otherwise you'll need to do a version check.

I suggest adding an explanation why you're doing that here, so people coming across this in the future won't need to git blame the code.

sage: results = DTR.summarize()
**********************************************************************
1 item had failures:
Expand All @@ -946,8 +951,8 @@
passed = []
failed = []
totalt = totalf = 0
for x in self._name2ft.items():
name, (f, t) = x
for x in self._stats.items():
name, (f, t, *_) = x
assert f <= t
totalt += t
totalf += f
Expand All @@ -972,10 +977,10 @@
print(self.DIVIDER, file=m)
print(count_noun(len(failed), "item"), "had failures:", file=m)
failed.sort()
for thing, (f, t) in failed:
for thing, (f, t, *_) in failed:
print(" %3d of %3d in %s" % (f, t, 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
Loading