cpvequal: use _pkg_str
authorZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 20:10:52 +0000 (13:10 -0700)
committerZac Medico <zmedico@gentoo.org>
Sun, 13 May 2012 20:10:52 +0000 (13:10 -0700)
pym/portage/dep/__init__.py
pym/portage/tests/dep/testStandalone.py

index 31ec75cf6dd89985de389f4609f4eb5eac54f90e..0c92857c4efc6660a4766633e05876f2383aac09 100644 (file)
@@ -76,16 +76,27 @@ def cpvequal(cpv1, cpv2):
 
        """
 
-       split1 = catpkgsplit(cpv1)
-       split2 = catpkgsplit(cpv2)
-       
-       if not split1 or not split2:
+       try:
+               try:
+                       split1 = cpv1.cpv_split
+               except AttributeError:
+                       cpv1 = _pkg_str(cpv1)
+                       split1 = cpv1.cpv_split
+
+               try:
+                       split2 = cpv2.cpv_split
+               except AttributeError:
+                       cpv2 = _pkg_str(cpv2)
+                       split2 = cpv2.cpv_split
+
+       except InvalidData:
                raise portage.exception.PortageException(_("Invalid data '%s, %s', parameter was not a CPV") % (cpv1, cpv2))
-       
-       if split1[0] != split2[0]:
+
+       if split1[0] != split2[0] or \
+               split1[1] != split2[1]:
                return False
-       
-       return (pkgcmp(split1[1:], split2[1:]) == 0)
+
+       return vercmp(cpv1.version, cpv2.version) == 0
 
 def strip_empty(myarr):
        """
index e9f01df03de9869091ac1843732761d5715372c5..f03f2d508cfab1b0dec0a1f8ad406f454f071dc5 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010 Gentoo Foundation
+# Copyright 2010-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from portage.tests import TestCase
@@ -29,7 +29,8 @@ class TestStandalone(TestCase):
                )
 
                for cpv1, cpv2, expected_result in test_cases:
-                       self.assertEqual(cpvequal(cpv1, cpv2), expected_result)
+                       self.assertEqual(cpvequal(cpv1, cpv2), expected_result,
+                               "cpvequal('%s', '%s') != %s" % (cpv1, cpv2, expected_result))
 
                for cpv1, cpv2 in test_cases_xfail:
                        self.assertRaisesMsg("cpvequal("+cpv1+", "+cpv2+")", \