8000 Impl. rename() method for NumpyTest class that allows redefining mapp… · numpy/numpy@2eb3a4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2eb3a4b

Browse files
committed
Impl. rename() method for NumpyTest class that allows redefining mapping between module name and test_<module name>.py file name. Fixed bug with output_exception argument.
1 parent 622e686 commit 2eb3a4b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

numpy/testing/numpytest.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ class NumpyTest:
206206
207207
Package is supposed to contain a directory tests/
208208
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.
209211
210212
test_*.py files are supposed to define a classes, derived
211213
from NumpyTestCase or unittest.TestCase, with methods having
@@ -221,8 +223,19 @@ def __init__(self, package=None):
221223
if package is None:
222224
from numpy.distutils.misc_util import get_frame
223225
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
225228
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
226239

227240
def _module_str(self, module):
228241
filename = module.__file__[-30:]
@@ -261,6 +274,10 @@ def _get_module_tests(self,module,level,verbosity):
261274
if short_module_name=='__init__':
262275
short_module_name = module.__name__.split('.')[-1]
263276

277+
short_module_name = self._rename_map.get(short_module_name,short_module_name)
278+
if short_module_name is None:
279+
return []
280+
264281
test_dir = os.path.join(d,'tests')
265282
test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')
266283

@@ -306,7 +323,7 @@ def _get_module_tests(self,module,level,verbosity):
306323
os.remove(test_file+pref+'c')
307324
except:
308325
self.warn(' !! FAILURE importing tests for %s' % mstr(module))
309-
output_exception(self.warn)
326+
output_exception(sys.stderr)
310327
return []
311328

312329
self.test_files.append(test_file)
@@ -322,7 +339,7 @@ def _get_suite_list(self, test_module, level, module_name='__main__'):
322339
return total_suite._tests
323340
except:
324341
self.warn(' !! FAILURE building tests for %s' % mstr(test_module))
325-
output_exception(self.warn)
342+
output_exception(sys.stderr)
326343
return []
327344
suite_list = []
328345
for name in dir(test_module):

0 commit comments

Comments
 (0)
0