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 1RD0Bg-0005c8-9S for garchives@archives.gentoo.org; Sun, 09 Oct 2011 20:41:32 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 755AE21C163; Sun, 9 Oct 2011 20:41:20 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 3FDE921C163 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 A664E1B4048 for ; Sun, 9 Oct 2011 20:41:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0A8ED80044 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: <7dc6f767eb849040bd933046a3f8aa2938e04b13.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: 7dc6f767eb849040bd933046a3f8aa2938e04b13 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: 64464a9e34d8e070acafb34a13331714 commit: 7dc6f767eb849040bd933046a3f8aa2938e04b13 Author: Mike Frysinger gentoo org> AuthorDate: Sun Oct 9 18:39:39 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=3D7dc6f767 tests: split up getTests into helper funcs to avoid duplication This avoids a little duplication between the getTestFromCommandLine and getTests funcs, and they'll get utilized even more in follow up patches. Signed-off-by: Mike Frysinger gentoo.org> --- pym/portage/tests/__init__.py | 37 +++++++++++++++++------------------= -- 1 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.p= y index 3897aba..7f1ed3f 100644 --- a/pym/portage/tests/__init__.py +++ b/pym/portage/tests/__init__.py @@ -55,7 +55,7 @@ def my_import(name): return mod =20 def getTestFromCommandLine(args, base_path): - ret =3D [] + result =3D [] for arg in args: realpath =3D os.path.realpath(arg) path =3D os.path.dirname(realpath) @@ -65,29 +65,16 @@ def getTestFromCommandLine(args, base_path): raise Exception("Invalid argument: '%s'" % arg) =20 mymodule =3D f[:-3] + result.extend(getTestsFromFiles(path, base_path, [mymodule])) + return result =20 - parent_path =3D path[len(base_path)+1:] - parent_module =3D ".".join(("portage", "tests", parent_path)) - parent_module =3D parent_module.replace('/', '.') - result =3D [] - - # Make the trailing / a . for module importing - modname =3D ".".join((parent_module, mymodule)) - mod =3D my_import(modname) - ret.append(unittest.TestLoader().loadTestsFromModule(mod)) - return ret - -def getTests(path, base_path): - """ - - path is the path to a given subdir ( 'portage/' for example) - This does a simple filter on files in that dir to give us modules - to import - - """ +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") ] files.sort() + return files + +def getTestsFromFiles(path, base_path, files): parent_path =3D path[len(base_path)+1:] parent_module =3D ".".join(("portage", "tests", parent_path)) parent_module =3D parent_module.replace('/', '.') @@ -99,6 +86,16 @@ def getTests(path, base_path): result.append(unittest.TestLoader().loadTestsFromModule(mod)) return result =20 +def getTests(path, base_path): + """ + + path is the path to a given subdir ( 'portage/' for example) + This does a simple filter on files in that dir to give us modules + to import + + """ + return getTestsFromFiles(path, base_path, getTestNames(path)) + class TextTestResult(_TextTestResult): """ We need a subclass of unittest._TextTestResult to handle tests with TOD= O