Skip to content

Commit 235a51e

Browse files
committed
TST: fix the xdoctest Parser drop-in example test
1 parent 1f517da commit 235a51e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

scipy_doctest/tests/test_runner.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ def __init__(self, config):
125125
def parse(self, string, name='<string>'):
126126
return self.xd.parse(string)
127127

128+
def get_examples(self, string, name='<string>'):
129+
"""
130+
Similar to doctest.DocTestParser.get_examples, only
131+
account for the fact that individual examples
132+
are instances of DoctestPart not doctest.Example
133+
"""
134+
return [x for x in self.parse(string, name)
135+
if isinstance(x, xdoctest.doctest_part.DoctestPart)]
136+
128137

129138
class TestParserDropIn:
130139
""" Test an alternative DoctestParser
@@ -139,9 +148,18 @@ def test_vanilla_parser(self):
139148

140149
@pytest.mark.skipif(not HAVE_XDOCTEST, reason="needs xdoctest")
141150
def test_xdoctest_parser(self):
151+
# Note that the # of examples differ from DTParser:
152+
# - xdoctest groups doctest lines with no 'want' output into a single
153+
# example.
154+
# - "examples" here are DoctestPart instances, which _almost_ quack
155+
# like `doctest.Example` but not completely.
142156
config = DTConfig(ParserKlass=XDParser)
143157
runner = DebugDTRunner(config=config)
144158
tests = DTFinder(config=config).find(module_cases.func3)
145159

146160
assert len(tests) == 1
147-
assert len(tests[0].examples) == 3
161+
assert len(tests[0].examples) == 2
162+
assert (tests[0].examples[0].source ==
163+
'import numpy as np\na = np.array([1, 2, 3, 4]) / 3'
164+
)
165+
assert tests[0].examples[1].source == 'print(a)'

0 commit comments

Comments
 (0)