summaryrefslogtreecommitdiffstats
path: root/pym
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-10-09 14:43:01 -0400
committerMike Frysinger <vapier@gentoo.org>2011-10-09 16:40:43 -0400
commit4dfb7a71ab9983e5bd0f2121062df04ffd6a748a (patch)
treedf1abf75d5bf6ec20d4ef9189ad119501b341157 /pym
parent0e32e6f3b950b6ca05724491cde8c9d04817d670 (diff)
downloadportage-4dfb7a71ab9983e5bd0f2121062df04ffd6a748a.tar.gz
portage-4dfb7a71ab9983e5bd0f2121062df04ffd6a748a.tar.bz2
portage-4dfb7a71ab9983e5bd0f2121062df04ffd6a748a.zip
tests: add --list flag to show available tests
Trying to guess at what runtests actually wants in terms of command line tests is pretty hard. Any invalid value just gives you an ugly traceback. So add a helper --list option so the user can easily figure out what the code wants *exactly*. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'pym')
-rw-r--r--pym/portage/tests/__init__.py55
1 files changed, 34 insertions, 21 deletions
diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index fa297b5bb..016a4e8d2 100644
--- a/pym/portage/tests/__init__.py
+++ b/pym/portage/tests/__init__.py
@@ -17,38 +17,28 @@ from portage import _encodings
from portage import _unicode_decode
def main():
-
- TEST_FILE = b'__test__'
- svn_dirname = b'.svn'
suite = unittest.TestSuite()
basedir = os.path.dirname(os.path.realpath(__file__))
- testDirs = []
usage = "usage: %s [options] [tests to run]" % os.path.basename(sys.argv[0])
parser = OptionParser(usage=usage)
+ parser.add_option("-l", "--list", help="list all tests",
+ action="store_true", dest="list_tests")
(options, args) = parser.parse_args(args=sys.argv)
+ if options.list_tests:
+ testdir = os.path.dirname(sys.argv[0])
+ for mydir in getTestDirs(basedir):
+ testsubdir = os.path.basename(mydir)
+ for name in getTestNames(mydir):
+ print("%s/%s/%s.py" % (testdir, testsubdir, name))
+ sys.exit(0)
+
if len(args) > 1:
suite.addTests(getTestFromCommandLine(args[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.
- for root, dirs, files in os.walk(basedir):
- if svn_dirname in dirs:
- dirs.remove(svn_dirname)
- try:
- root = _unicode_decode(root,
- encoding=_encodings['fs'], errors='strict')
- except UnicodeDecodeError:
- continue
-
- if TEST_FILE in files:
- testDirs.append(root)
-
- testDirs.sort()
- for mydir in testDirs:
+ for mydir in getTestDirs(basedir):
suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
return TextTestRunner(verbosity=2).run(suite)
@@ -73,6 +63,29 @@ def getTestFromCommandLine(args, base_path):
result.extend(getTestsFromFiles(path, base_path, [mymodule]))
return result
+def getTestDirs(base_path):
+ TEST_FILE = b'__test__'
+ svn_dirname = b'.svn'
+ testDirs = []
+
+ # 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.
+ for root, dirs, files in os.walk(base_path):
+ if svn_dirname in dirs:
+ dirs.remove(svn_dirname)
+ try:
+ root = _unicode_decode(root,
+ encoding=_encodings['fs'], errors='strict')
+ except UnicodeDecodeError:
+ continue
+
+ if TEST_FILE in files:
+ testDirs.append(root)
+
+ testDirs.sort()
+ return testDirs
+
def getTestNames(path):
files = os.listdir(path)
files = [ f[:-3] for f in files if f.startswith("test") and f.endswith(".py") ]