Skip to content

Commit 2760fd2

Browse files
authored
Merge pull request #162 from luxedo/FIX/161
FIX: iterable checks longest
2 parents bd7e851 + 1f5d4fb commit 2760fd2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

scipy_doctest/impl.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import warnings
33
import doctest
44
from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL
5+
from itertools import zip_longest
56

67
import numpy as np
78

@@ -328,7 +329,7 @@ def check_output(self, want, got, optionflags):
328329
except Exception:
329330
# heterog tuple, eg (1, np.array([1., 2.]))
330331
try:
331-
return all(self._do_check(w, g) for w, g in zip(a_want, a_got))
332+
return all(self._do_check(w, g) for w, g in zip_longest(a_want, a_got))
332333
except (TypeError, ValueError):
333334
return False
334335

scipy_doctest/tests/failure_cases.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
__all__ = ['func9', 'func10']
1+
__all__ = ['func9', 'func10', 'iterable_length_1', 'iterable_length_2']
2+
23

34
def func9():
45
"""
@@ -15,3 +16,17 @@ def func10():
1516
>>> import numpy as np
1617
>>> np.arraY([1, 2, 3])
1718
"""
19+
20+
21+
def iterable_length_1():
22+
"""
23+
>>> [1, 2, 3]
24+
[1, 2, 3, 4]
25+
"""
26+
27+
28+
def iterable_length_2():
29+
"""
30+
>>> [1, 2, 3]
31+
[1, 2]
32+
"""

scipy_doctest/tests/test_testmod.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ def test_user_context():
9999
config=config)
100100

101101

102+
def test_wrong_lengths():
103+
config = DTConfig()
104+
res, _ = _testmod(failure_cases,
105+
strategy=[failure_cases.iterable_length_1,
106+
failure_cases.iterable_length_2],
107+
config=config)
108+
assert res.failed == 2
109+
110+
102111
class TestLocalFiles:
103112
def test_local_files(self):
104113
# A doctest tries to open a local file. Test that it works

0 commit comments

Comments
 (0)