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 1QhhcC-0001MS-K5 for garchives@archives.gentoo.org; Fri, 15 Jul 2011 12:35:41 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B909C21C1AF; Fri, 15 Jul 2011 12:34:59 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 75B8321C1AF for ; Fri, 15 Jul 2011 12:34:59 +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 DA9AF1BC0EC for ; Fri, 15 Jul 2011 12:34:58 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id A686980051 for ; Fri, 15 Jul 2011 12:34:57 +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: <23f49980232e82722e418e87384f92acfa7109bd.mgorny@gentoo> 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: 23f49980232e82722e418e87384f92acfa7109bd Date: Fri, 15 Jul 2011 12:34:57 +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: 2cf4adb8c608d48d02b4f691f78542aa commit: 23f49980232e82722e418e87384f92acfa7109bd Author: Micha=C5=82 G=C3=B3rny gentoo org> AuthorDate: Fri Jul 15 12:06:48 2011 +0000 Commit: Micha=C5=82 G=C3=B3rny gentoo org> CommitDate: Fri Jul 15 12:06:48 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoopm.git;= a=3Dcommit;h=3D23f49980 Add tests for PMPackage. --- gentoopm/tests/__init__.py | 3 ++ gentoopm/tests/pkg.py | 87 ++++++++++++++++++++++++++++++++++++++= ++++++ setup.py | 1 + 3 files changed, 91 insertions(+), 0 deletions(-) diff --git a/gentoopm/tests/__init__.py b/gentoopm/tests/__init__.py index 02e2ac9..e96860f 100644 --- a/gentoopm/tests/__init__.py +++ b/gentoopm/tests/__init__.py @@ -57,3 +57,6 @@ class PackageNames(object): =20 repository =3D 'gentoo' """ Repository name guaranteed to match. """ + + envsafe_metadata_key =3D 'DESCRIPTION' + """ Metadata key which should be safe to match with environment.bz2. ""= " diff --git a/gentoopm/tests/pkg.py b/gentoopm/tests/pkg.py new file mode 100644 index 0000000..b57ff93 --- /dev/null +++ b/gentoopm/tests/pkg.py @@ -0,0 +1,87 @@ +#!/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 os.path + +from gentoopm.tests import PMTestCase, PackageNames + +class PackagesTestCase(PMTestCase): + def setUp(self): + self._inst_pkg =3D self.pm.installed.select(PackageNames.single_comple= te) + self._stack_pkg =3D self.pm.stack.select(PackageNames.single_complete) + self._pkgs =3D (self._inst_pkg, self._stack_pkg) + + def test_key_id(self): + """ Check whether package IDs are unique and keys are not. """ + for r in (self.pm.installed, self.pm.stack): + ids =3D set() + key =3D None + for p in r.filter(PackageNames.single_complete): + self.assertFalse(p.id in ids) + ids.add(p.id) + if key is not None: + self.assertEqual(p.key, key) + else: + key =3D p.key + + def test_path_exists(self): + """ Check whether the path returned is ok (if any). """ + for p in self._pkgs: + if p.path: + self.assertTrue(os.path.exists(p.path)) + + def test_atom_reverse(self): + """ Check whether the atom matches the same package. """ + for r in (self.pm.installed, self.pm.stack): + # get worst match + p =3D next(iter(sorted(r.filter(PackageNames.single_complete)))) + + self.assertEqual(p, r[p.atom]) + self.assertEqual(p.key, r.select(p.atom.slotted).key) + self.assertEqual(p.key, r.select(p.atom.unversioned).key) + + def test_metadata_inherited(self): + """ Check the INHERITED metadata var. It was known to cause problems + with pkgcore. """ + for p in self._pkgs: + p.metadata['INHERITED'] + + def test_metadata_dict_attr(self): + """ Check whether metadata is accessible with dict & attrs. """ + mks =3D ('EAPI', 'INHERITED', 'DESCRIPTION', 'CATEGORY') + for p in self._pkgs: + for k in mks: + self.assertEqual(p.metadata[k], getattr(p.metadata, k)) + + def test_metadata_invalid(self): + """ Check whether invalid metadata access raises an exception. """ + rk =3D 'FOOBAR' + for p in self._pkgs: + self.assertFalse(rk in p.metadata) + self.assertRaises(KeyError, lambda m, rk: m[rk], p.metadata, rk) + self.assertRaises(AttributeError, getattr, p.metadata, rk) + + def test_environ_dict(self): + """ Try to access environment.bz2 via dict. """ + rk =3D PackageNames.envsafe_metadata_key + for p in (self._inst_pkg,): + self.assertEqual(p.metadata[rk], p.environ[rk]) + + def test_environ_copy(self): + """ Try to access environment.bz2 via .copy(). """ + rk =3D PackageNames.envsafe_metadata_key + for p in (self._inst_pkg,): + self.assertEqual(p.metadata[rk], p.environ.copy(rk)[rk]) + + def test_environ_fork(self): + """ Test forking environment accessor. """ + rk =3D PackageNames.envsafe_metadata_key + for p in (self._inst_pkg,): + forkenv =3D p.environ.fork() + self.assertEqual(p.metadata[rk], forkenv[rk]) + del forkenv + + def tearDown(self): + pass diff --git a/setup.py b/setup.py index 2c2551f..cbe52d5 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.psets')) testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.repo')) maintestsuite.addTests(testsuite)