1 |
This avoids a little duplication between the getTestFromCommandLine and |
2 |
getTests funcs, and they'll get utilized even more in follow up patches. |
3 |
|
4 |
Signed-off-by: Mike Frysinger <vapier@g.o> |
5 |
--- |
6 |
pym/portage/tests/__init__.py | 37 +++++++++++++++++-------------------- |
7 |
1 files changed, 17 insertions(+), 20 deletions(-) |
8 |
|
9 |
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py |
10 |
index 3897aba..7f1ed3f 100644 |
11 |
--- a/pym/portage/tests/__init__.py |
12 |
+++ b/pym/portage/tests/__init__.py |
13 |
@@ -55,7 +55,7 @@ def my_import(name): |
14 |
return mod |
15 |
|
16 |
def getTestFromCommandLine(args, base_path): |
17 |
- ret = [] |
18 |
+ result = [] |
19 |
for arg in args: |
20 |
realpath = os.path.realpath(arg) |
21 |
path = os.path.dirname(realpath) |
22 |
@@ -65,29 +65,16 @@ def getTestFromCommandLine(args, base_path): |
23 |
raise Exception("Invalid argument: '%s'" % arg) |
24 |
|
25 |
mymodule = f[:-3] |
26 |
+ result.extend(getTestsFromFiles(path, base_path, [mymodule])) |
27 |
+ return result |
28 |
|
29 |
- parent_path = path[len(base_path)+1:] |
30 |
- parent_module = ".".join(("portage", "tests", parent_path)) |
31 |
- parent_module = parent_module.replace('/', '.') |
32 |
- result = [] |
33 |
- |
34 |
- # Make the trailing / a . for module importing |
35 |
- modname = ".".join((parent_module, mymodule)) |
36 |
- mod = my_import(modname) |
37 |
- ret.append(unittest.TestLoader().loadTestsFromModule(mod)) |
38 |
- return ret |
39 |
- |
40 |
-def getTests(path, base_path): |
41 |
- """ |
42 |
- |
43 |
- path is the path to a given subdir ( 'portage/' for example) |
44 |
- This does a simple filter on files in that dir to give us modules |
45 |
- to import |
46 |
- |
47 |
- """ |
48 |
+def getTestNames(path): |
49 |
files = os.listdir(path) |
50 |
files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ] |
51 |
files.sort() |
52 |
+ return files |
53 |
+ |
54 |
+def getTestsFromFiles(path, base_path, files): |
55 |
parent_path = path[len(base_path)+1:] |
56 |
parent_module = ".".join(("portage", "tests", parent_path)) |
57 |
parent_module = parent_module.replace('/', '.') |
58 |
@@ -99,6 +86,16 @@ def getTests(path, base_path): |
59 |
result.append(unittest.TestLoader().loadTestsFromModule(mod)) |
60 |
return result |
61 |
|
62 |
+def getTests(path, base_path): |
63 |
+ """ |
64 |
+ |
65 |
+ path is the path to a given subdir ( 'portage/' for example) |
66 |
+ This does a simple filter on files in that dir to give us modules |
67 |
+ to import |
68 |
+ |
69 |
+ """ |
70 |
+ return getTestsFromFiles(path, base_path, getTestNames(path)) |
71 |
+ |
72 |
class TextTestResult(_TextTestResult): |
73 |
""" |
74 |
We need a subclass of unittest._TextTestResult to handle tests with TODO |
75 |
-- |
76 |
1.7.6.1 |