public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-14 22:51 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-14 22:51 UTC (permalink / raw
  To: gentoo-commits

commit:     404cf6f20408e9a1cf0a0f2e0c2f12b0f62ca60e
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 14 22:12:59 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jul 14 22:13:32 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=404cf6f2

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=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+import unittest
+
+class PMTestCase(unittest.TestCase):
+	_pm = 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 = val
+
+class PMTestSuiteFactory(object):
+	def __init__(self, pm):
+		self._pm = pm
+
+	def __call__(self, tests):
+		for t in tests:
+			t.pm = self._pm
+		return unittest.TestSuite(tests)
+
+class PMTestLoader(unittest.TestLoader):
+	def __init__(self, pm):
+		self.suiteClass = PMTestSuiteFactory(pm)
+		unittest.TestLoader.__init__(self)
+
+	def loadTestsFromModule(self, mod):
+		if isinstance(mod, basestring):
+			mod = __import__(mod, fromlist=['.'], level=-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
 
 	def run(self):
-		import unittest
+		import unittest, doctest
+		import gentoopm.submodules, gentoopm.tests
 
-		tests = unittest.TestSuite()
+		maintestsuite = unittest.TestSuite()
+
+		for pm in gentoopm.submodules._supported_pms:
+			try:
+				pm_inst = gentoopm.submodules.get_pm(pm)
+			except ImportError:
+				print('%s not available, skipping tests.' % pm)
+			else:
+				l = gentoopm.tests.PMTestLoader(pm_inst)
+
+				testsuite = unittest.TestSuite()
+				maintestsuite.addTests(testsuite)
 
 		r = unittest.TextTestRunner()
-		res = r.run(tests)
+		res = r.run(maintestsuite)
 		sys.exit(0 if res.wasSuccessful() else 1)
 
 setup(
@@ -60,7 +72,8 @@ setup(
 			'gentoopm.bash',
 			'gentoopm.paludispm',
 			'gentoopm.pkgcorepm',
-			'gentoopm.portagepm'
+			'gentoopm.portagepm',
+			'gentoopm.tests'
 		],
 		scripts = [
 			'gentoopmq'



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-14 22:51 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-14 22:51 UTC (permalink / raw
  To: gentoo-commits

commit:     88cb9b5a3f27fec7bbdb5f07d101ac04dddeede5
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Thu Jul 14 22:50:10 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Thu Jul 14 22:50:10 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=88cb9b5a

Add tests for Atom class impl.

---
 gentoopm/tests/atom.py |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 setup.py               |    1 +
 2 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/gentoopm/tests/atom.py b/gentoopm/tests/atom.py
new file mode 100644
index 0000000..bee882d
--- /dev/null
+++ b/gentoopm/tests/atom.py
@@ -0,0 +1,57 @@
+#!/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.
+
+from gentoopm.exceptions import InvalidAtomStringError, AmbiguousPackageSetError
+from gentoopm.tests import PMTestCase
+
+class UserSpecifiedAtomTestCase(PMTestCase):
+	def setUp(self):
+		self._incomplete_atom = self.pm.Atom('portage')
+		self._complete_atom = self.pm.Atom('sys-apps/portage')
+		self._associated_atom = self._complete_atom.get_associated(self.pm.stack)
+
+	def test_invalid_atoms(self):
+		for atstr in ('<>foo', '=bar', '*/*::baz'):
+			self.assertRaises(InvalidAtomStringError, self.pm.Atom, atstr)
+
+	def test_incomplete_atom(self):
+		a = self._incomplete_atom
+		self.assertEqual(a.complete, False)
+		self.assertEqual(a.associated, False)
+
+	def test_complete_atom(self):
+		a = self._complete_atom
+		self.assertEqual(a.complete, True)
+		self.assertEqual(a.associated, False)
+
+	def test_atom_stringification(self):
+		for atstr in ('foo/bar', '>=baz/bar-100', 'foo/baz:10',
+				'bar/baz::foo', '>=foo/fooz-29.5:bazmania', '~baz/inga-4.1:2::foo'):
+			self.assertEqual(atstr, str(self.pm.Atom(atstr)))
+
+	def test_atom_association(self):
+		a = self._associated_atom
+		self.assertEqual(a.complete, True)
+		self.assertEqual(a.associated, True)
+
+	def test_incomplete_atom_association(self):
+		a = self._incomplete_atom.get_associated(self.pm.stack)
+		self.assertEqual(a.complete, True)
+		self.assertEqual(a.associated, True)
+
+	def test_ambiguous_atom_association(self):
+		# XXX: risky
+		ia = self.pm.Atom('pms')
+		self.assertRaises(AmbiguousPackageSetError, ia.get_associated,
+				self.pm.stack)
+
+	def test_atom_transformations(self):
+		a = self._associated_atom
+		cas = str(self._complete_atom)
+		self.assertEqual(str(a.slotted), '%s:0' % cas)
+		self.assertEqual(str(a.unversioned), cas)
+
+	def tearDown(self):
+		pass

diff --git a/setup.py b/setup.py
index ba0553b..92fc300 100755
--- a/setup.py
+++ b/setup.py
@@ -53,6 +53,7 @@ class TestCommand(Command):
 				l = gentoopm.tests.PMTestLoader(pm_inst)
 
 				testsuite = unittest.TestSuite()
+				testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.atom'))
 				maintestsuite.addTests(testsuite)
 
 		r = unittest.TextTestRunner()



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-15  9:52 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-15  9:52 UTC (permalink / raw
  To: gentoo-commits

commit:     5af231d34b76a38848b95fb7d7212246996edf7b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 08:54:39 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 08:54:39 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=5af231d3

Add tests for config.

---
 gentoopm/tests/config.py |   19 +++++++++++++++++++
 setup.py                 |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/gentoopm/tests/config.py b/gentoopm/tests/config.py
new file mode 100644
index 0000000..599e06d
--- /dev/null
+++ b/gentoopm/tests/config.py
@@ -0,0 +1,19 @@
+#!/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.
+
+from gentoopm.tests import PMTestCase
+
+class ConfigTestCase(PMTestCase):
+	def setUp(self):
+		self._conf = self.pm.config
+
+	def test_userpriv(self):
+		if self._conf.userpriv_enabled:
+			# root's no userpriv
+			self.assertNotEqual(self._conf.userpriv_uid, 0)
+			self.assertNotEqual(self._conf.userpriv_gid, 0)
+
+	def tearDown(self):
+		pass

diff --git a/setup.py b/setup.py
index 92fc300..5eac8d5 100755
--- a/setup.py
+++ b/setup.py
@@ -54,6 +54,7 @@ class TestCommand(Command):
 
 				testsuite = unittest.TestSuite()
 				testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.atom'))
+				testsuite.addTests(l.loadTestsFromModule('gentoopm.tests.config'))
 				maintestsuite.addTests(testsuite)
 
 		r = unittest.TextTestRunner()



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-15  9:52 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-15  9:52 UTC (permalink / raw
  To: gentoo-commits

commit:     4b2eb6c85228e08265ddad6732dbd38588c3c1bb
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 09:19:16 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 09:20:33 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=4b2eb6c8

Add general tests for repository properties.

---
 gentoopm/tests/__init__.py |    3 +++
 gentoopm/tests/repo.py     |   39 +++++++++++++++++++++++++++++++++++++++
 setup.py                   |    1 +
 3 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/gentoopm/tests/__init__.py b/gentoopm/tests/__init__.py
index f430917..eced9c1 100644
--- a/gentoopm/tests/__init__.py
+++ b/gentoopm/tests/__init__.py
@@ -51,3 +51,6 @@ class PackageNames(object):
 
 	multiple = 'pms'
 	""" Incomplete atom matching multiple packages. """
+
+	repository = 'gentoo'
+	""" Repository name guaranteed to match. """

diff --git a/gentoopm/tests/repo.py b/gentoopm/tests/repo.py
new file mode 100644
index 0000000..e30f77f
--- /dev/null
+++ b/gentoopm/tests/repo.py
@@ -0,0 +1,39 @@
+#!/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.
+
+from gentoopm.tests import PMTestCase, PackageNames
+
+class RepositoriesTestCase(PMTestCase):
+	def setUp(self):
+		self._stack = self.pm.stack
+		self._repo = self.pm.repositories[PackageNames.repository]
+
+	def test_repo_iter(self):
+		needle = PackageNames.repository
+		for r in self.pm.repositories:
+			if r.name == needle:
+				break
+		else:
+			self.assertTrue(r.name == needle)
+
+	def test_repo_contains(self):
+		self.assertTrue(PackageNames.repository in self.pm.repositories)
+
+	def test_repo_reverse_mapping(self):
+		r = self._repo
+		self.assertTrue(r.path in self.pm.repositories)
+		self.assertEqual(r, self.pm.repositories[r.path])
+
+	def test_stack_repos_equiv(self):
+		patom = PackageNames.single_complete
+		plist = set([x.id for x in self._stack.filter(patom)])
+		for r in self.pm.repositories:
+			for p in r.filter(patom):
+				self.assertTrue(p.id in plist)
+				plist.remove(p.id)
+		self.assertFalse(plist) # empty
+
+	def tearDown(self):
+		pass

diff --git a/setup.py b/setup.py
index 5eac8d5..6c5a481 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.repo'))
 				maintestsuite.addTests(testsuite)
 
 		r = unittest.TextTestRunner()



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-15  9:52 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-15  9:52 UTC (permalink / raw
  To: gentoo-commits

commit:     b751801e385a079c1b59eca10741497e4737d742
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 09:48:43 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 09:48:43 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=b751801e

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 = 'pms'
 	""" Incomplete atom matching multiple packages. """
 
+	empty = 'example/example'
+	""" Atom matching no packages. """
+
 	repository = '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=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 2-clause BSD license.
+
+from gentoopm.exceptions import AmbiguousPackageSetError, EmptyPackageSetError
+from gentoopm.tests import PMTestCase, PackageNames
+
+class IterChecker(object):
+	def __init__(self, iterable):
+		self._it = iter(iterable)
+
+	def __nonzero__(self):
+		try:
+			next(self._it)
+		except StopIteration:
+			return False
+		else:
+			return True
+
+class PackageSetsTestCase(PMTestCase):
+	def setUp(self):
+		self._inst = self.pm.installed
+		self._stack = self.pm.stack
+		self._repo = self.pm.repositories[PackageNames.repository]
+		self._repos = (self._inst, self._stack, self._repo)
+
+	def test_filter_atom(self):
+		at = PackageNames.single_complete
+		for r in self._repos:
+			self.assertTrue(IterChecker(r.filter(at)))
+
+	def test_filter_atom_incomplete(self):
+		at = 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 = PackageNames.multiple
+		for r in self._repos:
+			keys = set()
+			for p in r.filter(at):
+				keys.add(p.key)
+			self.assertTrue(len(keys) > 1)
+
+	def test_filter_atom_empty(self):
+		at = PackageNames.empty
+		for r in self._repos:
+			self.assertFalse(IterChecker(r.filter(at)))
+
+	def test_select_atom(self):
+		at = PackageNames.single_complete
+		for r in self._repos:
+			self.assertTrue(r.select(at))
+
+	def test_select_atom_incomplete(self):
+		at = PackageNames.single
+		for r in self._repos:
+			self.assertTrue(r.select(at))
+
+	def test_select_atom_multiple(self):
+		at = PackageNames.multiple
+		for r in self._repos:
+			self.assertRaises(AmbiguousPackageSetError, r.select, at)
+
+	def test_select_atom_empty(self):
+		at = PackageNames.empty
+		for r in self._repos:
+			self.assertRaises(EmptyPackageSetError, r.select, at)
+
+	def test_getitem_atom(self):
+		at = PackageNames.single_complete
+		for r in (self._stack, self._repo):
+			self.assertRaises(AmbiguousPackageSetError, lambda r, at: r[at], r, at)
+		self.assertTrue(self._inst[at])
+
+	def test_getitem_atom_empty(self):
+		at = PackageNames.empty
+		for r in self._repos:
+			self.assertRaises(EmptyPackageSetError, lambda r, at: r[at], r, at)
+
+	def test_nonzero_true(self):
+		at = PackageNames.single_complete
+		for r in self._repos:
+			pset = r.filter(at)
+			self.assertTrue(IterChecker(pset))
+			self.assertTrue(pset)
+
+	def test_nonzero_false(self):
+		at = PackageNames.empty
+		for r in self._repos:
+			pset = r.filter(at)
+			self.assertFalse(IterChecker(pset))
+			self.assertFalse(pset)
+
+	def test_contains_atom(self):
+		at = PackageNames.single_complete
+		for r in self._repos:
+			self.assertTrue(at in r)
+
+	def test_contains_atom_multiple(self):
+		at = PackageNames.multiple
+		for r in self._repos:
+			self.assertTrue(at in r)
+
+	def test_contains_atom_empty(self):
+		at = 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 = 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)
 



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-15 12:34 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-15 12:34 UTC (permalink / raw
  To: gentoo-commits

commit:     d098127ffa9cf44970432b889b99a03120e888ca
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jul 15 10:59:30 2011 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Fri Jul 15 10:59:30 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoopm.git;a=commit;h=d098127f

Rename tests.pkg -> tests.psets.

---
 gentoopm/tests/{pkg.py => psets.py} |    0
 setup.py                            |    2 +-
 2 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/gentoopm/tests/pkg.py b/gentoopm/tests/psets.py
similarity index 100%
rename from gentoopm/tests/pkg.py
rename to gentoopm/tests/psets.py

diff --git a/setup.py b/setup.py
index 4318a8e..2c2551f 100755
--- a/setup.py
+++ b/setup.py
@@ -55,7 +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)
 



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/
@ 2011-07-15 12:34 Michał Górny
  0 siblings, 0 replies; 7+ messages in thread
From: Michał Górny @ 2011-07-15 12:34 UTC (permalink / raw
  To: gentoo-commits

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)



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-15 12:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-15 12:34 [gentoo-commits] proj/gentoopm:master commit in: /, gentoopm/tests/ Michał Górny
  -- strict thread matches above, loose matches on Subject: below --
2011-07-15 12:34 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox