From a7f75239b5ffe51e714d71660d0e7b8a00a30ee4 Mon Sep 17 00:00:00 2001 From: Sebastian Luther Date: Tue, 10 Aug 2010 23:29:16 +0200 Subject: [PATCH] Tests: add dep/testStandalone. Test small functions here. Currently: cpvequal, flatten --- pym/portage/tests/dep/testStandalone.py | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 pym/portage/tests/dep/testStandalone.py diff --git a/pym/portage/tests/dep/testStandalone.py b/pym/portage/tests/dep/testStandalone.py new file mode 100644 index 000000000..a5d661cc3 --- /dev/null +++ b/pym/portage/tests/dep/testStandalone.py @@ -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) -- 2.26.2