summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Luther <SebastianLuther@gmx.de>2010-08-08 22:52:50 +0200
committerZac Medico <zmedico@gentoo.org>2010-08-08 17:17:11 -0700
commitfef6bc0af3f527ded24fd82465383f363865e4b6 (patch)
tree53ce793290fe85598bc6ddfcb197e6d97585db6b
parent026f630247c7ec77f4bb46e01091b9f0c2b74201 (diff)
downloadportage-fef6bc0af3f527ded24fd82465383f363865e4b6.tar.gz
portage-fef6bc0af3f527ded24fd82465383f363865e4b6.tar.bz2
portage-fef6bc0af3f527ded24fd82465383f363865e4b6.zip
Tests: Let ./runTests take files as argument to run only the test in these files
-rw-r--r--pym/portage/tests/__init__.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 393ecf78c..bd41f1ee8 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -26,6 +26,10 @@ def main():
basedir = os.path.dirname(os.path.realpath(__file__))
testDirs = []
+ if len(sys.argv) > 1:
+ suite.addTests(getTestFromCommandLine(sys.argv[1:], basedir))
+ return TextTestRunner(verbosity=2).run(suite)
+
# the os.walk help mentions relative paths as being quirky
# I was tired of adding dirs to the list, so now we add __test__
# to each dir we want tested.
@@ -52,6 +56,29 @@ def my_import(name):
mod = getattr(mod, comp)
return mod
+def getTestFromCommandLine(args, base_path):
+ ret = []
+ for arg in args:
+ realpath = os.path.realpath(arg)
+ path = os.path.dirname(realpath)
+ f = realpath[len(path)+1:]
+
+ if not f.startswith("test") or not f.endswith(".py"):
+ raise Exception("Invalid argument: '%s'" % arg)
+
+ mymodule = f[:-3]
+
+ parent_path = path[len(base_path)+1:]
+ parent_module = ".".join(("portage", "tests", parent_path))
+ parent_module = parent_module.replace('/', '.')
+ result = []
+
+ # Make the trailing / a . for module importing
+ modname = ".".join((parent_module, mymodule))
+ mod = my_import(modname)
+ ret.append(unittest.TestLoader().loadTestsFromModule(mod))
+ return ret
+
def getTests(path, base_path):
"""