FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo Portage Developer

 
 
LinkBack Thread Tools
 
Old 10-09-2011, 06:53 PM
Mike Frysinger
 
Default 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>
---
pym/portage/tests/__init__.py | 55 +++++++++++++++++++++++++---------------
1 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py
index 07be2f6..6cce487 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]" % 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") ]
--
1.7.6.1
 

Thread Tools




All times are GMT. The time now is 08:04 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org