Linux Archive

Linux Archive (http://www.linux-archive.org/)
-   Gentoo Portage Developer (http://www.linux-archive.org/gentoo-portage-developer/)
-   -   tests: split up getTests into helper funcs to avoid duplication (http://www.linux-archive.org/gentoo-portage-developer/585460-tests-split-up-gettests-into-helper-funcs-avoid-duplication.html)

Mike Frysinger 10-09-2011 06:53 PM

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>
---
pym/portage/tests/__init__.py | 37 +++++++++++++++++--------------------
1 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 3897aba..7f1ed3f 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().loadTestsFromModu le(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().loadTestsFromM odule(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
--
1.7.6.1


All times are GMT. The time now is 11:57 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.