@@ -206,6 +206,8 @@ class NumpyTest:
206
206
207
207
Package is supposed to contain a directory tests/
208
208
with test_*.py files where * refers to the names of submodules.
209
+ See .rename() method to redefine name mapping between test_*.py files
210
+ and names of submodules.
209
211
210
212
test_*.py files are supposed to define a classes, derived
211
213
from NumpyTestCase or unittest.TestCase, with methods having
@@ -221,8 +223,19 @@ def __init__(self, package=None):
221
223
if package is None :
222
224
from numpy .distutils .misc_util import get_frame
223
225
f = get_frame (1 )
224
- package = f .f_locals ['__name__' ]
226
+ package = f .f_locals .get ('__name__' ,f .f_globals .get ('__name__' ,None ))
227
+ assert package is not None
225
228
self .package = package
229
+ self ._rename_map = {}
230
+
231
+ def rename (self , ** kws ):
232
+ """ Apply renaming submodule test file test_<name>.py to test_<newname>.py.
233
+ Usage: self.rename(name='newname') before calling self.test() method.
234
+ If 'newname' is None, then no tests will be executed for a given module.
235
+ """
236
+ for k ,v in kws .items ():
237
+ self ._rename_map [k ] = v
238
+ return
226
239
227
240
def _module_str (self , module ):
228
241
filename = module .__file__ [- 30 :]
@@ -261,6 +274,10 @@ def _get_module_tests(self,module,level,verbosity):
261
274
if short_module_name == '__init__' :
262
275
short_module_name = module .__name__ .split ('.' )[- 1 ]
263
276
277
+ short_module_name = self ._rename_map .get (short_module_name ,short_module_name )
278
+ if short_module_name is None :
279
+ return []
280
+
264
281
test_dir = os .path .join (d ,'tests' )
265
282
test_file = os .path .join (test_dir ,'test_' + short_module_name + '.py' )
266
283
@@ -306,7 +323,7 @@ def _get_module_tests(self,module,level,verbosity):
306
323
os .remove (test_file + pref + 'c' )
307
324
except :
308
325
self .warn (' !! FAILURE importing tests for %s' % mstr (module ))
309
- output_exception (self . warn )
326
+ output_exception (sys . stderr )
310
327
return []
311
328
312
329
self .test_files .append (test_file )
@@ -322,7 +339,7 @@ def _get_suite_list(self, test_module, level, module_name='__main__'):
322
339
return total_suite ._tests
323
340
except :
324
341
self .warn (' !! FAILURE building tests for %s' % mstr (test_module ))
325
- output_exception (self . warn )
342
+ output_exception (sys . stderr )
326
343
return []
327
344
suite_list = []
328
345
for name in dir (test_module ):
0 commit comments