From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
Date: Fri, 15 Jul 2011 12:34:57 +0000 (UTC) [thread overview]
Message-ID: <23f49980232e82722e418e87384f92acfa7109bd.mgorny@gentoo> (raw)
commit: 23f49980232e82722e418e87384f92acfa7109bd
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 12:06:48 2011 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 12:06:48 2011 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=23f49980
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):
repository = 'gentoo'
""" Repository name guaranteed to match. """
+
+ envsafe_metadata_key = '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=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# 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 = self.pm.installed.select(PackageNames.single_complete)
+ self._stack_pkg = self.pm.stack.select(PackageNames.single_complete)
+ self._pkgs = (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 = set()
+ key = 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 = 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 = 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 = ('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 = '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 = 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 = 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 = PackageNames.envsafe_metadata_key
+ for p in (self._inst_pkg,):
+ forkenv = 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 = 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)
next reply other threads:[~2011-07-15 12:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-15 12:34 Michał Górny [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-07-15 12:34 [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/ Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-15 9:52 Michał Górny
2011-07-14 22:51 Michał Górny
2011-07-14 22:51 Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23f49980232e82722e418e87384f92acfa7109bd.mgorny@gentoo \
--to=mgorny@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox