From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RD0Bc-0005a9-2k for garchives@archives.gentoo.org; Sun, 09 Oct 2011 20:41:28 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3C5B021C1DA; Sun, 9 Oct 2011 20:41:21 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E208221C1DA for ; Sun, 9 Oct 2011 20:41:20 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 506EF1B404D for ; Sun, 9 Oct 2011 20:41:20 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 629EB80052 for ; Sun, 9 Oct 2011 20:41:19 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <4dfb7a71ab9983e5bd0f2121062df04ffd6a748a.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/tests/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/tests/__init__.py X-VCS-Directories: pym/portage/tests/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 4dfb7a71ab9983e5bd0f2121062df04ffd6a748a Date: Sun, 9 Oct 2011 20:41:19 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: c81a44f63bb0df1a6f9970ea946662b3 commit: 4dfb7a71ab9983e5bd0f2121062df04ffd6a748a Author: Mike Frysinger gentoo org> AuthorDate: Sun Oct 9 18:43:01 2011 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sun Oct 9 20:40:43 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D4dfb7a71 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 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__.p= y index fa297b5..016a4e8 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 =20 def main(): - - TEST_FILE =3D b'__test__' - svn_dirname =3D b'.svn' suite =3D unittest.TestSuite() basedir =3D os.path.dirname(os.path.realpath(__file__)) - testDirs =3D [] =20 usage =3D "usage: %s [options] [tests to run]" % os.path.basename(sys.a= rgv[0]) parser =3D OptionParser(usage=3Dusage) + parser.add_option("-l", "--list", help=3D"list all tests", + action=3D"store_true", dest=3D"list_tests") (options, args) =3D parser.parse_args(args=3Dsys.argv) =20 + if options.list_tests: + testdir =3D os.path.dirname(sys.argv[0]) + for mydir in getTestDirs(basedir): + testsubdir =3D 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=3D2).run(suite) =20 - # 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 =3D _unicode_decode(root, - encoding=3D_encodings['fs'], errors=3D'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=3D2).run(suite) =20 @@ -73,6 +63,29 @@ def getTestFromCommandLine(args, base_path): result.extend(getTestsFromFiles(path, base_path, [mymodule])) return result =20 +def getTestDirs(base_path): + TEST_FILE =3D b'__test__' + svn_dirname =3D b'.svn' + testDirs =3D [] + + # 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 =3D _unicode_decode(root, + encoding=3D_encodings['fs'], errors=3D'strict') + except UnicodeDecodeError: + continue + + if TEST_FILE in files: + testDirs.append(root) + + testDirs.sort() + return testDirs + def getTestNames(path): files =3D os.listdir(path) files =3D [ f[:-3] for f in files if f.startswith("test") and f.endswit= h(".py") ]