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 1Qhf4c-0007a2-HW for garchives@archives.gentoo.org; Fri, 15 Jul 2011 09:52:42 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9906921C16B; Fri, 15 Jul 2011 09:52:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 50BED21C167 for ; Fri, 15 Jul 2011 09:52:29 +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 BFB8C2AC316 for ; Fri, 15 Jul 2011 09:52:28 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B888580057 for ; Fri, 15 Jul 2011 09:52:27 +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: Subject: [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/ X-VCS-Repository: proj/gentoopm X-VCS-Files: gentoopm/tests/__init__.py gentoopm/tests/pkg.py setup.py X-VCS-Directories: / gentoopm/tests/ X-VCS-Committer: mgorny X-VCS-Committer-Name: Michał Górny X-VCS-Revision: b751801e385a079c1b59eca10741497e4737d742 Date: Fri, 15 Jul 2011 09:52:27 +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: f62c4ca8965a78426333c31a03957dc5 commit: b751801e385a079c1b59eca10741497e4737d742 Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Fri Jul 15 09:48:43 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Fri Jul 15 09:48:43 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3Db751801e Add tests for package sets. --- gentoopm/tests/__init__.py | 3 + gentoopm/tests/pkg.py | 113 ++++++++++++++++++++++++++++++++++++++= ++++++ setup.py | 1 + 3 files changed, 117 insertions(+), 0 deletions(-) diff --git a/gentoopm/tests/__init__.py b/gentoopm/tests/__init__.py index eced9c1..7b52fae 100644 --- a/gentoopm/tests/__init__.py +++ b/gentoopm/tests/__init__.py @@ -52,5 +52,8 @@ class PackageNames(object): multiple =3D 'pms' """ Incomplete atom matching multiple packages. """ =20 + empty =3D 'example/example' + """ Atom matching no packages. """ + repository =3D 'gentoo' """ Repository name guaranteed to match. """ diff --git a/gentoopm/tests/pkg.py b/gentoopm/tests/pkg.py new file mode 100644 index 0000000..47ca02e --- /dev/null +++ b/gentoopm/tests/pkg.py @@ -0,0 +1,113 @@ +#!/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. + +from gentoopm.exceptions import AmbiguousPackageSetError, EmptyPackageSe= tError +from gentoopm.tests import PMTestCase, PackageNames + +class IterChecker(object): + def __init__(self, iterable): + self._it =3D iter(iterable) + + def __nonzero__(self): + try: + next(self._it) + except StopIteration: + return False + else: + return True + +class PackageSetsTestCase(PMTestCase): + def setUp(self): + self._inst =3D self.pm.installed + self._stack =3D self.pm.stack + self._repo =3D self.pm.repositories[PackageNames.repository] + self._repos =3D (self._inst, self._stack, self._repo) + + def test_filter_atom(self): + at =3D PackageNames.single_complete + for r in self._repos: + self.assertTrue(IterChecker(r.filter(at))) + + def test_filter_atom_incomplete(self): + at =3D PackageNames.single + for r in self._repos: + self.assertTrue(IterChecker(r.filter(at))) + + def test_filter_atom_multiple(self): + """ Check whether multi-matching atoms return multiple packages. """ + at =3D PackageNames.multiple + for r in self._repos: + keys =3D set() + for p in r.filter(at): + keys.add(p.key) + self.assertTrue(len(keys) > 1) + + def test_filter_atom_empty(self): + at =3D PackageNames.empty + for r in self._repos: + self.assertFalse(IterChecker(r.filter(at))) + + def test_select_atom(self): + at =3D PackageNames.single_complete + for r in self._repos: + self.assertTrue(r.select(at)) + + def test_select_atom_incomplete(self): + at =3D PackageNames.single + for r in self._repos: + self.assertTrue(r.select(at)) + + def test_select_atom_multiple(self): + at =3D PackageNames.multiple + for r in self._repos: + self.assertRaises(AmbiguousPackageSetError, r.select, at) + + def test_select_atom_empty(self): + at =3D PackageNames.empty + for r in self._repos: + self.assertRaises(EmptyPackageSetError, r.select, at) + + def test_getitem_atom(self): + at =3D PackageNames.single_complete + for r in (self._stack, self._repo): + self.assertRaises(AmbiguousPackageSetError, lambda r, at: r[at], r, a= t) + self.assertTrue(self._inst[at]) + + def test_getitem_atom_empty(self): + at =3D PackageNames.empty + for r in self._repos: + self.assertRaises(EmptyPackageSetError, lambda r, at: r[at], r, at) + + def test_nonzero_true(self): + at =3D PackageNames.single_complete + for r in self._repos: + pset =3D r.filter(at) + self.assertTrue(IterChecker(pset)) + self.assertTrue(pset) + + def test_nonzero_false(self): + at =3D PackageNames.empty + for r in self._repos: + pset =3D r.filter(at) + self.assertFalse(IterChecker(pset)) + self.assertFalse(pset) + + def test_contains_atom(self): + at =3D PackageNames.single_complete + for r in self._repos: + self.assertTrue(at in r) + + def test_contains_atom_multiple(self): + at =3D PackageNames.multiple + for r in self._repos: + self.assertTrue(at in r) + + def test_contains_atom_empty(self): + at =3D PackageNames.empty + for r in self._repos: + self.assertFalse(at in r) + + def tearDown(self): + pass diff --git a/setup.py b/setup.py index 6c5a481..4318a8e 100755 --- a/setup.py +++ b/setup.py @@ -55,6 +55,7 @@ class TestCommand(Command): testsuite =3D unittest.TestSuite() testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.atom')) testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.config')) + testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.pkg')) testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.repo')) maintestsuite.addTests(testsuite) =20