1 |
Trying to guess at what runtests actually wants in terms of command line |
2 |
tests is pretty hard. Any invalid value just gives you an ugly traceback. |
3 |
So add a helper --list option so the user can easily figure out what the |
4 |
code wants *exactly*. |
5 |
|
6 |
Signed-off-by: Mike Frysinger <vapier@g.o> |
7 |
--- |
8 |
pym/portage/tests/__init__.py | 55 +++++++++++++++++++++++++--------------- |
9 |
1 files changed, 34 insertions(+), 21 deletions(-) |
10 |
|
11 |
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py |
12 |
index 07be2f6..6cce487 100644 |
13 |
--- a/pym/portage/tests/__init__.py |
14 |
+++ b/pym/portage/tests/__init__.py |
15 |
@@ -17,38 +17,28 @@ from portage import _encodings |
16 |
from portage import _unicode_decode |
17 |
|
18 |
def main(): |
19 |
- |
20 |
- TEST_FILE = b'__test__' |
21 |
- svn_dirname = b'.svn' |
22 |
suite = unittest.TestSuite() |
23 |
basedir = os.path.dirname(os.path.realpath(__file__)) |
24 |
- testDirs = [] |
25 |
|
26 |
usage = "usage: %s [options] [tests to run]" % sys.argv[0] |
27 |
parser = OptionParser(usage=usage) |
28 |
+ parser.add_option("-l", "--list", help="list all tests", |
29 |
+ action="store_true", dest="list_tests") |
30 |
(options, args) = parser.parse_args(args=sys.argv) |
31 |
|
32 |
+ if options.list_tests: |
33 |
+ testdir = os.path.dirname(sys.argv[0]) |
34 |
+ for mydir in getTestDirs(basedir): |
35 |
+ testsubdir = os.path.basename(mydir) |
36 |
+ for name in getTestNames(mydir): |
37 |
+ print("%s/%s/%s.py" % (testdir, testsubdir, name)) |
38 |
+ sys.exit(0) |
39 |
+ |
40 |
if len(args) > 1: |
41 |
suite.addTests(getTestFromCommandLine(args[1:], basedir)) |
42 |
return TextTestRunner(verbosity=2).run(suite) |
43 |
|
44 |
- # the os.walk help mentions relative paths as being quirky |
45 |
- # I was tired of adding dirs to the list, so now we add __test__ |
46 |
- # to each dir we want tested. |
47 |
- for root, dirs, files in os.walk(basedir): |
48 |
- if svn_dirname in dirs: |
49 |
- dirs.remove(svn_dirname) |
50 |
- try: |
51 |
- root = _unicode_decode(root, |
52 |
- encoding=_encodings['fs'], errors='strict') |
53 |
- except UnicodeDecodeError: |
54 |
- continue |
55 |
- |
56 |
- if TEST_FILE in files: |
57 |
- testDirs.append(root) |
58 |
- |
59 |
- testDirs.sort() |
60 |
- for mydir in testDirs: |
61 |
+ for mydir in getTestDirs(basedir): |
62 |
suite.addTests(getTests(os.path.join(basedir, mydir), basedir) ) |
63 |
return TextTestRunner(verbosity=2).run(suite) |
64 |
|
65 |
@@ -73,6 +63,29 @@ def getTestFromCommandLine(args, base_path): |
66 |
result.extend(getTestsFromFiles(path, base_path, [mymodule])) |
67 |
return result |
68 |
|
69 |
+def getTestDirs(base_path): |
70 |
+ TEST_FILE = b'__test__' |
71 |
+ svn_dirname = b'.svn' |
72 |
+ testDirs = [] |
73 |
+ |
74 |
+ # the os.walk help mentions relative paths as being quirky |
75 |
+ # I was tired of adding dirs to the list, so now we add __test__ |
76 |
+ # to each dir we want tested. |
77 |
+ for root, dirs, files in os.walk(base_path): |
78 |
+ if svn_dirname in dirs: |
79 |
+ dirs.remove(svn_dirname) |
80 |
+ try: |
81 |
+ root = _unicode_decode(root, |
82 |
+ encoding=_encodings['fs'], errors='strict') |
83 |
+ except UnicodeDecodeError: |
84 |
+ continue |
85 |
+ |
86 |
+ if TEST_FILE in files: |
87 |
+ testDirs.append(root) |
88 |
+ |
89 |
+ testDirs.sort() |
90 |
+ return testDirs |
91 |
+ |
92 |
def getTestNames(path): |
93 |
files = os.listdir(path) |
94 |
files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ] |
95 |
-- |
96 |
1.7.6.1 |