3
3
import numpy as np
4
4
5
5
from . import finder_cases
6
+ from . import finder_cases_2
6
7
from ..util import get_all_list , get_public_objects
7
8
from ..impl import DTFinder , DTConfig
8
9
from ..frontend import find_doctests
@@ -142,10 +143,13 @@ def test_explicit_object_list():
142
143
objs = [finder_cases .Klass ]
143
144
tests = find_doctests (finder_cases , strategy = objs )
144
145
146
+ names = sorted ([test .name for test in tests ])
147
+
145
148
base = 'scipy_doctest.tests.finder_cases'
146
- assert ([test .name for test in tests ] ==
147
- [f'{ base } .Klass' , f'{ base } .Klass.meth' , f'{ base } .Klass.meth_2' ,
148
- f'{ base } .Klass.__weakref__' ])
149
+ expected = sorted ([f'{ base } .Klass' , f'{ base } .Klass.__weakref__' ,
150
+ f'{ base } .Klass.meth' , f'{ base } .Klass.meth_2' ,])
151
+
152
+ assert names == expected
149
153
150
154
151
155
def test_explicit_object_list_with_module ():
@@ -155,21 +159,27 @@ def test_explicit_object_list_with_module():
155
159
objs = [finder_cases , finder_cases .Klass ]
156
160
tests = find_doctests (finder_cases , strategy = objs )
157
161
162
+ names = sorted ([test .name for test in tests ])
163
+
158
164
base = 'scipy_doctest.tests.finder_cases'
159
- assert ([test .name for test in tests ] ==
160
- [base , f'{ base } .Klass' , f'{ base } .Klass.meth' , f'{ base } .Klass.meth_2' ,
161
- f'{ base } .Klass.__weakref__' ])
165
+ expected = sorted ([base , f'{ base } .Klass' , f'{ base } .Klass.__weakref__' ,
166
+ f'{ base } .Klass.meth' , f'{ base } .Klass.meth_2' ])
167
+
168
+ assert names == expected
162
169
163
170
164
171
def test_find_doctests_api ():
165
172
# Test that the module itself is included with strategy='api'
166
173
tests = find_doctests (finder_cases , strategy = 'api' )
167
174
175
+ names = sorted ([test .name for test in tests ])
176
+
168
177
base = 'scipy_doctest.tests.finder_cases'
169
- assert ([test .name for test in tests ] ==
170
- [base + '.func' , base + '.Klass' , base + '.Klass.meth' ,
178
+ expected = sorted ([base + '.func' , base + '.Klass' , base + '.Klass.meth' ,
171
179
base + '.Klass.meth_2' , base + '.Klass.__weakref__' , base ])
172
180
181
+ assert names == expected
182
+
173
183
174
184
def test_dtfinder_config ():
175
185
config = DTConfig ()
@@ -183,3 +193,30 @@ def test_descriptors_get_collected():
183
193
names = [test .name for test in tests ]
184
194
assert 'numpy.dtype.kind' in names # was previously missing
185
195
196
+
197
+ @pytest .mark .parametrize ('strategy' , [None , 'api' ])
198
+ def test_private_superclasses (strategy ):
199
+ # Test that methods from inherited private superclasses get collected
200
+ tests = find_doctests (finder_cases_2 , strategy = strategy )
201
+
202
+ names = set (test .name .split ('.' )[- 1 ] for test in tests )
203
+ expected_names = ['finder_cases_2' , 'public_method' , 'private_method' ]
204
+ if strategy == 'api' :
205
+ expected_names += ['__weakref__' ]
206
+
207
+ assert len (tests ) == len (expected_names )
208
+ assert names == set (expected_names )
209
+
210
+
211
+ def test_private_superclasses_2 ():
212
+ # similar to test_private_superclass, only with an explicit strategy=list
213
+ tests = find_doctests (finder_cases_2 , strategy = [finder_cases_2 .Klass ])
214
+
215
+ names = set (test .name .split ('.' )[- 1 ] for test in tests )
216
+ expected_names = ['public_method' , 'private_method' , '__weakref__' ]
217
+
218
+ assert len (tests ) == len (expected_names )
219
+ assert names == set (expected_names )
220
+
221
+
222
+
0 commit comments