Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 5ba3c41

Browse files
author
Release Manager
committed
Trac #31036: fixdoctests fails on multiline tests
{{{#!diff diff --git a/src/sage/geometry/polyhedron/backend_normaliz.py b/src/sage/geometry/polyhedron/backend_normaliz.py index f47d07f..eb01e1740c 100644 --- a/src/sage/geometry/polyhedron/backend_normaliz.py +++ b/src/sage/geometry/polyhedron/backend_normaliz.py @@ -103,7 +103,8 @@ class Polyhedron_normaliz(Polyhedron_base): EXAMPLES:: sage: p = Polyhedron(vertices=[(0,0),(1,0),(0,1)], rays=[(1,1)], # optional - pynormaliz - ....: lines=[], backend='normaliz') + A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 3 vertices and 1 ray + ....: lines=[], backend='normaliz'); p sage: TestSuite(p).run() # optional - pynormaliz }}} I just added the printing of `p` and run `sage --fixdoctests`. `fixdoctests` assumed that all tests have only one line so far. In addition we now fix error testing according to our conventions: Before running `fixdoctests` {{{#!diff EXAMPLES:: + sage: raise ValueError sage: rt2 = AA(sqrt(2)); rt2 1.414213562373095? sage: rt3 = AA(sqrt(3)); rt3 }}} After running `fixdoctests`: {{{#!diff EXAMPLES:: + sage: raise ValueError + Traceback (most recent call last): + ... + ValueError sage: rt2 = AA(sqrt(2)); rt2 1.414213562373095? sage: rt3 = AA(sqrt(3)); rt3 }}} Before running `fixdoctests`: {{{ + sage: raise TypeError("the error has changed") + Traceback (most recent call last): + ... + ValueError }}} After runninng `fixdoctests`: {{{#!diff EXAMPLES:: + sage: raise TypeError("the error has changed") + Traceback (most recent call last): + ... + TypeError: the error has changed sage: rt2 = AA(sqrt(2)); rt2 1.414213562373095? sage: rt3 = AA(sqrt(3)); rt3 }}} If a non-empty doctest raises an error after changes, then `fixdoctests` needs to run twice (probably not very likely usecase). URL: https://trac.sagemath.org/31036 Reported by: gh-kliem Ticket author(s): Jonathan Kliem Reviewer(s): Markus Wageringel
2 parents 7217db8 + 776f4d9 commit 5ba3c41

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/bin/sage-fixdoctests

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,31 @@ for block in doctests:
6262
comma = block.find(', in ') # we try to extract the line number which gives the test failure
6363
if line == -1 or comma==-1: continue # but if something goes wrong we give up
6464
line_num=eval(block[line+5:comma])
65+
66+
# Take care of multiline examples.
67+
if 'Expected' in block:
68+
i1 = block.index('Failed example')
69+
i2 = block.index('Expected')
70+
example_len = block[i1:i2].count('\n') - 1
71+
line_num += example_len - 1
72+
6573
if 'Expected nothing' in block:
6674
exp = block.find('Expected nothing')
6775
block='\n'+block[exp+17:] # so that split('\nGot:\n') does not fail below
6876
elif 'Expected:' in block:
6977
exp = block.find('Expected:\n')
7078
block=block[exp+10:]
79+
elif 'Exception raised' in block:
80+
exp = block.find('Exception raised')
81+
block='\nGot:\n'+block[exp+17:]
7182
else:
7283
continue
73-
if block[-21:]=='Got:\n <BLANKLINE>\n':
84+
# Error testing.
85+
if 'Traceback (most recent call last):' in block:
86+
expected, got = block.split('\nGot:\n')
87+
got = got.splitlines()
88+
got = [' Traceback (most recent call last):', ' ...', got[-1]]
89+
elif block[-21:]=='Got:\n <BLANKLINE>\n':
7490
expected=block[:-22]
7591
got=['']
7692
else:

0 commit comments

Comments
 (0)