Skip to content

Commit ada9cf9

Browse files
authored
Merge pull request #164 from luxedo/ENH/156
Enh/156 - Distinguish lists of arrays from tuples of arrays
2 parents 2760fd2 + 5ce2cb4 commit ada9cf9

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-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)) and
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: 16 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+
'tuple_and_list_1', 'tuple_and_list_2']
23

34

45
def func9():
@@ -30,3 +31,17 @@ def iterable_length_2():
3031
>>> [1, 2, 3]
3132
[1, 2]
3233
"""
34+
35+
36+
def tuple_and_list_1():
37+
"""
38+
>>> [0, 1, 2]
39+
(0, 1, 2)
40+
"""
41+
42+
43+
def tuple_and_list_2():
44+
"""
45+
>>> (0, 1, 2)
46+
[0, 1, 2]
47+
"""

scipy_doctest/tests/module_cases.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,19 @@ def test_cmplx_nan():
190190
>>> 1j*np.complex128(np.nan)
191191
np.complex128(nan+nanj)
192192
"""
193+
194+
195+
def array_and_list_1():
196+
"""
197+
>>> import numpy as np
198+
>>> np.array([1, 2, 3])
199+
[1, 2, 3]
200+
"""
201+
202+
203+
def array_and_list_2():
204+
"""
205+
>>> import numpy as np
206+
>>> [1, 2, 3]
207+
array([1, 2, 3])
208+
"""

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_tuple_and_list():
112+
config = DTConfig()
113+
res, _ = _testmod(failure_cases,
114+
strategy=[failure_cases.tuple_and_list_1,
115+
failure_cases.tuple_and_list_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)