Tests: add dep/testStandalone. Test small functions here. Currently: cpvequal, flatten
authorSebastian Luther <SebastianLuther@gmx.de>
Tue, 10 Aug 2010 21:29:16 +0000 (23:29 +0200)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Aug 2010 05:31:02 +0000 (22:31 -0700)
pym/portage/tests/dep/testStandalone.py [new file with mode: 0644]

diff --git a/pym/portage/tests/dep/testStandalone.py b/pym/portage/tests/dep/testStandalone.py
new file mode 100644 (file)
index 0000000..a5d661c
--- /dev/null
@@ -0,0 +1,50 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+from portage.tests import TestCase
+from portage.dep import cpvequal, flatten
+from portage.exception import PortageException
+
+class TestStandalone(TestCase):
+       """ Test some small functions portage.dep
+       """
+
+       def testCPVequal(self):
+
+               test_cases = (
+                       ( "sys-apps/portage-2.1","sys-apps/portage-2.1", True ),
+                       ( "sys-apps/portage-2.1","sys-apps/portage-2.0", False ),
+                       ( "sys-apps/portage-2.1","sys-apps/portage-2.1-r1", False ),
+                       ( "sys-apps/portage-2.1-r1","sys-apps/portage-2.1", False ),
+                       ( "sys-apps/portage-2.1_alpha3","sys-apps/portage-2.1", False ),
+                       ( "sys-apps/portage-2.1_alpha3_p6","sys-apps/portage-2.1_alpha3", False ),
+                       ( "sys-apps/portage-2.1_alpha3","sys-apps/portage-2.1", False ),
+                       ( "sys-apps/portage-2.1","sys-apps/X-2.1", False ),
+                       ( "sys-apps/portage-2.1","portage-2.1", False ),
+               )
+               
+               test_cases_xfail = (
+                       ( "sys-apps/portage","sys-apps/portage" ),
+                       ( "sys-apps/portage-2.1-6","sys-apps/portage-2.1-6" ),
+               )
+
+               for cpv1, cpv2, expected_result in test_cases:
+                       self.assertEqual(cpvequal(cpv1, cpv2), expected_result)
+
+               for cpv1, cpv2 in test_cases_xfail:
+                       self.assertRaisesMsg("cpvequal("+cpv1+", "+cpv2+")", \
+                               PortageException, cpvequal, cpv1, cpv2)
+
+
+       def testFlattenl(self):
+
+               test_cases = (
+                       ( [], [] ),
+                       ( [[]], [] ),
+                       ( [[], 1], [1] ),
+                       ( [1, [2, 3, [4]]], [1, 2, 3, 4] ),
+                       ( [1, [2], 3, [4]], [1, 2, 3, 4] ),
+               )
+
+               for not_flat, flat in test_cases:
+                       self.assertEqual(flatten(not_flat), flat)