Skip to content

Commit 855b4da

Browse files
authored
Merge pull request #180 from scipy/descriptors
BUG: collect doctests from docstrings of data descriptors
2 parents 5113870 + 005c641 commit 855b4da

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

scipy_doctest/impl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import warnings
3+
import inspect
34
import doctest
45
from doctest import NORMALIZE_WHITESPACE, ELLIPSIS, IGNORE_EXCEPTION_DETAIL
56
from itertools import zip_longest
@@ -538,6 +539,13 @@ def find(self, obj, name=None, module=None, globs=None, extraglobs=None):
538539
# XXX: does this make similar checks in testmod/testfile duplicate?
539540
if module not in self.config.skiplist:
540541
tests = super().find(obj, name, module, globs, extraglobs)
542+
543+
if inspect.isclass(obj):
544+
for name_, method in inspect.getmembers(obj):
545+
if inspect.isdatadescriptor(method):
546+
tests += super().find(
547+
method, f'{name}.{name_}', module, globs, extraglobs
548+
)
541549
return tests
542550

543551

scipy_doctest/tests/test_finder.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import pytest
22

3+
import numpy as np
4+
35
from . import finder_cases
46
from ..util import get_all_list, get_public_objects
57
from ..impl import DTFinder, DTConfig
68
from ..frontend import find_doctests
79

10+
811
def test_get_all_list():
912
items, depr, other = get_all_list(finder_cases)
1013
assert sorted(items) == ['Klass', 'func']
@@ -111,6 +114,7 @@ def test_get_doctests_strategy_api(self):
111114
# - *private* stuff, which is not in `__all__`
112115
wanted_names = ['Klass', 'Klass.meth']
113116
wanted_names = [base] + [base + '.' + n for n in wanted_names]
117+
wanted_names += [f'{base}.Klass.__weakref__']
114118

115119
assert sorted(names) == sorted(wanted_names)
116120

@@ -129,6 +133,7 @@ def test_get_doctests_strategy_list(self):
129133
# - the 'base' module (via the strategy=<list>)
130134
wanted_names = ['Klass', 'Klass.meth']
131135
wanted_names = [base + '.' + n for n in wanted_names]
136+
wanted_names += [f'{base}.Klass.__weakref__']
132137

133138
assert sorted(names) == sorted(wanted_names)
134139

@@ -139,7 +144,8 @@ def test_explicit_object_list():
139144

140145
base = 'scipy_doctest.tests.finder_cases'
141146
assert ([test.name for test in tests] ==
142-
[base + '.Klass', base + '.Klass.meth', base + '.Klass.meth_2'])
147+
[f'{base}.Klass', f'{base}.Klass.meth', f'{base}.Klass.meth_2',
148+
f'{base}.Klass.__weakref__'])
143149

144150

145151
def test_explicit_object_list_with_module():
@@ -151,7 +157,8 @@ def test_explicit_object_list_with_module():
151157

152158
base = 'scipy_doctest.tests.finder_cases'
153159
assert ([test.name for test in tests] ==
154-
[base, base + '.Klass', base + '.Klass.meth', base + '.Klass.meth_2'])
160+
[base, f'{base}.Klass', f'{base}.Klass.meth', f'{base}.Klass.meth_2',
161+
f'{base}.Klass.__weakref__'])
155162

156163

157164
def test_find_doctests_api():
@@ -161,10 +168,18 @@ def test_find_doctests_api():
161168
base = 'scipy_doctest.tests.finder_cases'
162169
assert ([test.name for test in tests] ==
163170
[base + '.func', base + '.Klass', base + '.Klass.meth',
164-
base + '.Klass.meth_2', base])
171+
base + '.Klass.meth_2', base + '.Klass.__weakref__', base])
165172

166173

167174
def test_dtfinder_config():
168175
config = DTConfig()
169176
finder = DTFinder(config=config)
170177
assert finder.config is config
178+
179+
180+
@pytest.mark.skipif(np.__version__ < '2', reason="XXX check if works on numpy 1.x")
181+
def test_descriptors_get_collected():
182+
tests = find_doctests(np, strategy=[np.dtype])
183+
names = [test.name for test in tests]
184+
assert 'numpy.dtype.kind' in names # was previously missing
185+

0 commit comments

Comments
 (0)