summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2007-01-10 18:46:35 +0000
committerZac Medico <zmedico@gentoo.org>2007-01-10 18:46:35 +0000
commit05ea706cebe6d291556b685de23fb35014d5dbb5 (patch)
tree3bacadd149a45bf2ce3bbcaf9d783ea81cc9d701 /tests
parent45007e96015507405b5fc398fbc6e6402ef5a25f (diff)
downloadportage-05ea706cebe6d291556b685de23fb35014d5dbb5.tar.gz
portage-05ea706cebe6d291556b685de23fb35014d5dbb5.tar.bz2
portage-05ea706cebe6d291556b685de23fb35014d5dbb5.zip
Fix module loading.
svn path=/main/trunk/; revision=5532
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
index 71d699770..2808ed5a4 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -3,19 +3,27 @@
# Distributed under the terms of the GNU General Public License v2
# $Id$
-import unittest
+import os, unittest
def main():
- testDirs = ["portage/", "portage_util/"]
+ testDirs = ["portage", "portage_util"]
suite = unittest.TestSuite()
- for dir in testDirs:
- suite.addTests(getTests(dir))
+ basedir = os.path.dirname(__file__)
+ for mydir in testDirs:
+ suite.addTests(getTests(os.path.join(basedir, mydir)))
return unittest.TextTestRunner(verbosity=2).run(suite)
+def my_import(name):
+ mod = __import__(name)
+ components = name.split('.')
+ for comp in components[1:]:
+ mod = getattr(mod, comp)
+ return mod
+
def getTests( path ):
"""
@@ -27,14 +35,14 @@ def getTests( path ):
import os
files = os.listdir( path )
files = [ f[:-3] for f in files if f.startswith("test_") and f.endswith(".py") ]
-
+ parent_module = ".".join(("tests", os.path.basename(path)))
result = []
- for file in files:
+ for mymodule in files:
try:
# Make the trailing / a . for module importing
- path2 = path[:-1] + "." + file
- mod = __import__( path2, globals(), locals(), [path[-1]])
+ modname = ".".join((parent_module, mymodule))
+ mod = my_import(modname)
result.append( unittest.TestLoader().loadTestsFromModule(mod) )
except ImportError:
- pass
+ raise
return result