Skip to content

Commit f8504ae

Browse files
authored
ENH: Remove <BLANKLINE> tags before evaluating (#216)
* ENH: Remove <BLANKLINE> tags before evaluating Doctest stops collecting output on a blank line: if the expected output includes a blank line, that is indicated with a `<BLANKLINE>` tag. That tag is not valid python, so it needs to be removed before evaluating output for np.isclose. reviewed at #216
1 parent 8bb8bee commit f8504ae

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

scipy_doctest/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def check_output(self, want, got, optionflags):
356356
# OK then, convert strings to objects
357357
ns = dict(self.config.check_namespace)
358358
try:
359-
a_want = eval(want, dict(ns))
359+
a_want = eval(want.replace("<BLANKLINE>", ""), dict(ns))
360360
a_got = eval(got, dict(ns))
361361
except Exception:
362362
# Maybe we're printing a numpy array? This produces invalid python

scipy_doctest/tests/module_cases.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ def list_of_tuples_numeric():
271271
"""
272272

273273

274+
def rank_3_array_repr():
275+
"""Check recovery of rank-3 array from doctest-style repr.
276+
277+
>>> import numpy as np
278+
>>> np.arange(24).reshape(2, 3, 4)
279+
array([[[ 0, 1, 2, 3],
280+
[ 4, 5, 6, 7],
281+
[ 8, 9, 10, 11]],
282+
<BLANKLINE>
283+
[[12, 13, 14, 15],
284+
[16, 17, 18, 19],
285+
[20, 21, 22, 23]]])
286+
"""
287+
288+
274289
# This is used by test_testmod.py::test_public_object_discovery
275290
# While in test we only need __all__ to be not empty, let's make it correct, too.
276291
__all__ = [x for x in vars().keys() if not x.startswith("_")]

0 commit comments

Comments
 (0)