summaryrefslogtreecommitdiff
path: root/numpy/testing/numpytest.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-04-26 19:51:49 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-04-26 19:51:49 +0000
commitb01cd88166e84fd8510ad74c231a5aaf0ae4879d (patch)
tree26a8cd337509106e7142e397a91f21023352023a /numpy/testing/numpytest.py
parentf6c56c197f7b3fd245615e2c9bc862b815309c57 (diff)
downloadnumpy-b01cd88166e84fd8510ad74c231a5aaf0ae4879d.tar.gz
Added importall function that recursively imports modules. Convinient for detecting any import problems.
Diffstat (limited to 'numpy/testing/numpytest.py')
-rw-r--r--numpy/testing/numpytest.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/numpy/testing/numpytest.py b/numpy/testing/numpytest.py
index c9a255e55..55e4e0fc8 100644
--- a/numpy/testing/numpytest.py
+++ b/numpy/testing/numpytest.py
@@ -11,6 +11,7 @@ import traceback
__all__ = ['set_package_path', 'set_local_path', 'restore_path',
'IgnoreException', 'NumpyTestCase', 'NumpyTest',
'ScipyTestCase', 'ScipyTest', # for backward compatibility
+ 'importall'
]
DEBUG=0
@@ -477,3 +478,27 @@ class NumpyTest:
sys.stdout.flush()
ScipyTest = NumpyTest
+
+def importall(package):
+ """
+ Try recursively to import all subpackages under package.
+ """
+ if isinstance(package,str):
+ package = __import__(package)
+
+ package_name = package.__name__
+ package_dir = os.path.dirname(package.__file__)
+ for subpackage_name in os.listdir(package_dir):
+ subdir = os.path.join(package_dir, subpackage_name)
+ if not os.path.isdir(subdir):
+ continue
+ if not os.path.isfile(os.path.join(subdir,'__init__.py')):
+ continue
+ name = package_name+'.'+subpackage_name
+ try:
+ exec 'import %s as m' % (name)
+ except Exception, msg:
+ print 'Failed importing %s: %s' %(name, msg)
+ continue
+ importall(m)
+ return