Skip to content

Commit b84a0da

Browse files
author
Release Manager
committed
gh-39102: Show continuation lines when doctest crashes I think this makes more sense. Normally the format is like ``` sage: code(code) ## line 1234 ## 'result' ``` or ``` sage: code(code) code(code) ## line 1234 ## 'result' ``` with the patch, the display becomes ``` sage: code(code) ....: code(code) ## line 1234 ## 'result' ``` ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39102 Reported by: user202729 Reviewer(s): Julian Rüth
2 parents bfbac28 + 41b39bb commit b84a0da

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ jobs:
107107
uses: tj-actions/changed-files@v45
108108
with:
109109
# File extensions for doctests per sage.doctest.control.skipfile
110+
# Also src/sage/doctests/tests/ are excluded because of nodoctest file
111+
# which would make sage.doctest.control.skipdir return True
110112
files_yaml: |
111113
configures:
112114
- 'build/pkgs/*/spkg-configure.m4'
@@ -118,6 +120,7 @@ jobs:
118120
doctests:
119121
- 'src/**/*.{py,pyx,pxd,pxi,sage,spyx,rst,tex}'
120122
- '!src/{setup,conftest*}.py'
123+
- '!src/sage/doctest/tests/*'
121124
122125
- name: Determine targets to build
123126
id: build-targets
@@ -246,7 +249,7 @@ jobs:
246249
./sage -python -m pytest -c tox.ini -qq --doctest --collect-only || true
247250
shell: sh .ci/docker-exec-script.sh BUILD /sage {0}
248251

249-
- name: Test changed files (sage -t --new)
252+
- name: Test changed files
250253
if: (success() || failure()) && steps.container.outcome == 'success' && steps.changed-files.outputs.doctests_all_changed_files
251254
run: |
252255
export MAKE="make -j2 --output-sync=recurse" SAGE_NUM_THREADS=4

src/sage/doctest/forker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ def _run(self, test, compileflags, out):
664664
# We print the example we're running for easier debugging
665665
# if this file times out or crashes.
666666
with OriginalSource(example):
667-
print("sage: " + example.source[:-1] + " ## line %s ##" % (test.lineno + example.lineno + 1))
667+
assert example.source.endswith("\n"), example
668+
print("sage: " + example.source[:-1].replace("\n", "\n....: ") + " ## line %s ##" % (test.lineno + example.lineno + 1))
668669
# Update the position so that result comparison works
669670
self._fakeout.getvalue()
670671
if not quiet:

src/sage/doctest/test.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,21 @@
295295
...
296296
16
297297
298-
A different kind of crash::
298+
A different kind of crash (also test printing of line continuation ``...:``,
299+
represented by ``<DOTSCOLON>`` below)::
299300
300-
sage: subprocess.call(["sage", "-t", "--warn-long", "0", # long time
301-
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds)
301+
sage: # long time
302+
sage: proc = subprocess.run(["sage", "-t", "--warn-long", "0",
303+
....: "--random-seed=0", "--optional=sage", "fail_and_die.rst"], **kwds,
304+
....: stdout=subprocess.PIPE, text=True)
305+
sage: # the replacements are needed to avoid the strings being interpreted
306+
....: # specially by the doctesting framework
307+
sage: print(proc.stdout.replace('sage:', 'sage<COLON>').replace('....:', '<DOTSCOLON>'))
302308
Running doctests...
303309
Doctesting 1 file.
304310
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst
305311
**********************************************************************
306-
File "fail_and_die.rst", line 5, in sage.doctest.tests.fail_and_die
312+
File "fail_and_die.rst", line 8, in sage.doctest.tests.fail_and_die
307313
Failed example:
308314
this_gives_a_NameError
309315
Exception raised:
@@ -313,11 +319,18 @@
313319
Killed due to kill signal
314320
**********************************************************************
315321
Tests run before process (pid=...) failed:
316-
...
322+
sage<COLON> import time, signal ## line 4 ##
323+
sage<COLON> print(1,
324+
<DOTSCOLON> 2) ## line 5 ##
325+
1 2
326+
sage<COLON> this_gives_a_NameError ## line 8 ##
327+
sage<COLON> os.kill(os.getpid(), signal.SIGKILL) ## line 9 ##
328+
**********************************************************************
317329
----------------------------------------------------------------------
318330
sage -t --warn-long 0.0 --random-seed=0 fail_and_die.rst # Killed due to kill signal
319331
----------------------------------------------------------------------
320332
...
333+
sage: proc.returncode
321334
16
322335
323336
Test that ``sig_on_count`` is checked correctly::
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
The :exc:`NameError` raised on the second line should be displayed, even
2-
if we crash immediately afterwards::
2+
if we crash immediately afterwards (also test printing of line continuation)::
33

44
sage: import time, signal
5+
sage: print(1,
6+
....: 2)
7+
1 2
58
sage: this_gives_a_NameError
69
sage: os.kill(os.getpid(), signal.SIGKILL)

0 commit comments

Comments
 (0)