Skip to content

Commit ec6f9dc

Browse files
committed
ENH: Validate type for list or tuple
1 parent 2760fd2 commit ec6f9dc

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

scipy_doctest/impl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ def check_output(self, want, got, optionflags):
323323
else:
324324
return self.check_output(want_again, got_again, optionflags)
325325

326+
# Validate data type if list or tuple
327+
is_list_or_tuple = (isinstance(a_want, (list, tuple)) or
328+
isinstance(a_got, (list, tuple)))
329+
if is_list_or_tuple and type(a_want) is not type(a_got):
330+
return False
331+
326332
# ... and defer to numpy
327333
try:
328334
return self._do_check(a_want, a_got)

scipy_doctest/tests/failure_cases.py

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

34

45
def func9():
@@ -30,3 +31,18 @@ def iterable_length_2():
3031
>>> [1, 2, 3]
3132
[1, 2]
3233
"""
34+
35+
36+
def different_iteralbes_1():
37+
"""
38+
>>> [0, 1, 2]
39+
(0, 1, 2)
40+
"""
41+
42+
43+
def different_iteralbes_2():
44+
"""
45+
>>> import numpy as np
46+
>>> np.array([0, 1, 2])
47+
[0, 1, 2]
48+
"""

scipy_doctest/tests/test_testmod.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ def test_wrong_lengths():
108108
assert res.failed == 2
109109

110110

111+
def test_different_iterables():
112+
config = DTConfig()
113+
res, _ = _testmod(failure_cases,
114+
strategy=[failure_cases.different_iteralbes_1,
115+
failure_cases.different_iteralbes_2],
116+
config=config)
117+
assert res.failed == 2
118+
119+
111120
class TestLocalFiles:
112121
def test_local_files(self):
113122
# A doctest tries to open a local file. Test that it works

0 commit comments

Comments
 (0)