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 1QhUkS-0000mK-6K for garchives@archives.gentoo.org; Thu, 14 Jul 2011 22:51:12 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C4C9B21C184; Thu, 14 Jul 2011 22:51:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 92B9821C0FE for ; Thu, 14 Jul 2011 22:51:03 +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 1ABAA1B405B for ; Thu, 14 Jul 2011 22:51:03 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 74FEE8003F for ; Thu, 14 Jul 2011 22:51:02 +0000 (UTC) From: "Michał Górny" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Michał Górny" Message-ID: <404cf6f20408e9a1cf0a0f2e0c2f12b0f62ca60e.mgorny@gentoo> Subject: [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/tests/__init__.py setup.py X-VCS-Directories: / gentoopm/tests/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: 404cf6f20408e9a1cf0a0f2e0c2f12b0f62ca60e Date: Thu, 14 Jul 2011 22:51:02 +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: 0f4de1d972735e6562e50856a91c154d commit: 404cf6f20408e9a1cf0a0f2e0c2f12b0f62ca60e Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Thu Jul 14 22:12:59 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Thu Jul 14 22:13:32 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3D404cf6f2 Support loading test suites for all PMs. --- gentoopm/tests/__init__.py | 38 ++++++++++++++++++++++++++++++++++++++ setup.py | 21 +++++++++++++++++---- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/gentoopm/tests/__init__.py b/gentoopm/tests/__init__.py new file mode 100644 index 0000000..40f0b75 --- /dev/null +++ b/gentoopm/tests/__init__.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +# vim:fileencoding=3Dutf-8 +# (c) 2011 Micha=C5=82 G=C3=B3rny +# Released under the terms of the 2-clause BSD license. + +import unittest + +class PMTestCase(unittest.TestCase): + _pm =3D None + + @property + def pm(self): + assert(self._pm is not None) + return self._pm + + @pm.setter + def pm(self, val): + assert(self._pm is None) + self._pm =3D val + +class PMTestSuiteFactory(object): + def __init__(self, pm): + self._pm =3D pm + + def __call__(self, tests): + for t in tests: + t.pm =3D self._pm + return unittest.TestSuite(tests) + +class PMTestLoader(unittest.TestLoader): + def __init__(self, pm): + self.suiteClass =3D PMTestSuiteFactory(pm) + unittest.TestLoader.__init__(self) + + def loadTestsFromModule(self, mod): + if isinstance(mod, basestring): + mod =3D __import__(mod, fromlist=3D['.'], level=3D-1) + return unittest.TestLoader.loadTestsFromModule(self, mod) diff --git a/setup.py b/setup.py index 01f5366..ba0553b 100755 --- a/setup.py +++ b/setup.py @@ -39,12 +39,24 @@ class TestCommand(Command): pass =20 def run(self): - import unittest + import unittest, doctest + import gentoopm.submodules, gentoopm.tests =20 - tests =3D unittest.TestSuite() + maintestsuite =3D unittest.TestSuite() + + for pm in gentoopm.submodules._supported_pms: + try: + pm_inst =3D gentoopm.submodules.get_pm(pm) + except ImportError: + print('%s not available, skipping tests.' % pm) + else: + l =3D gentoopm.tests.PMTestLoader(pm_inst) + + testsuite =3D unittest.TestSuite() + maintestsuite.addTests(testsuite) =20 r =3D unittest.TextTestRunner() - res =3D r.run(tests) + res =3D r.run(maintestsuite) sys.exit(0 if res.wasSuccessful() else 1) =20 setup( @@ -60,7 +72,8 @@ setup( 'gentoopm.bash', 'gentoopm.paludispm', 'gentoopm.pkgcorepm', - 'gentoopm.portagepm' + 'gentoopm.portagepm', + 'gentoopm.tests' ], scripts =3D [ 'gentoopmq'