summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-10-09 14:39:39 -0400
committerMike Frysinger <vapier@gentoo.org>2011-10-09 16:40:43 -0400
commit7dc6f767eb849040bd933046a3f8aa2938e04b13 (patch)
treed7b56bcad123793debdf648b41e7d4885ecb5de7 /pym
parent949b30548b21630b1423f5ead8335bc5eb0bbc92 (diff)
downloadportage-7dc6f767eb849040bd933046a3f8aa2938e04b13.tar.gz
portage-7dc6f767eb849040bd933046a3f8aa2938e04b13.tar.bz2
portage-7dc6f767eb849040bd933046a3f8aa2938e04b13.zip
tests: split up getTests into helper funcs to avoid duplication
This avoids a little duplication between the getTestFromCommandLine and getTests funcs, and they'll get utilized even more in follow up patches. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/tests/__init__.py37
1 files changed, 17 insertions, 20 deletions
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 3897aba2b..7f1ed3f70 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -55,7 +55,7 @@ def my_import(name):
return mod
def getTestFromCommandLine(args, base_path):
- ret = []
+ result = []
for arg in args:
realpath = os.path.realpath(arg)
path = os.path.dirname(realpath)
@@ -65,29 +65,16 @@ def getTestFromCommandLine(args, base_path):
raise Exception("Invalid argument: '%s'" % arg)
mymodule = f[:-3]
+ result.extend(getTestsFromFiles(path, base_path, [mymodule]))
+ return result
- 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):
- """
-
- path is the path to a given subdir ( 'portage/' for example)
- This does a simple filter on files in that dir to give us modules
- to import
-
- """
+def getTestNames(path):
files = os.listdir(path)
files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]
files.sort()
+ return files
+
+def getTestsFromFiles(path, base_path, files):
parent_path = path[len(base_path)+1:]
parent_module = ".".join(("portage", "tests", parent_path))
parent_module = parent_module.replace('/', '.')
@@ -99,6 +86,16 @@ def getTests(path, base_path):
result.append(unittest.TestLoader().loadTestsFromModule(mod))
return result
+def getTests(path, base_path):
+ """
+
+ path is the path to a given subdir ( 'portage/' for example)
+ This does a simple filter on files in that dir to give us modules
+ to import
+
+ """
+ return getTestsFromFiles(path, base_path, getTestNames(path))
+
class TextTestResult(_TextTestResult):
"""
We need a subclass of unittest._TextTestResult to handle tests with TODO