Fix isvalidatom() so tests pass, and add a USE deps case to the tests.
authorZac Medico <zmedico@gentoo.org>
Sun, 25 May 2008 02:56:41 +0000 (02:56 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 25 May 2008 02:56:41 +0000 (02:56 -0000)
svn path=/main/trunk/; revision=10399

pym/portage/dep.py
pym/portage/tests/dep/test_isvalidatom.py

index 6881b17346ad98cc4e7ed9b3073336c53992d4f8..75d4f4c471dfad96c61c898a1276a9d0828b22dd 100644 (file)
@@ -557,6 +557,7 @@ def dep_getusedeps( depend ):
                open_bracket = depend.find( '[', open_bracket+1 )
        return tuple(use_list)
 
+_valid_category = re.compile("^\w[\w-]*")
 _invalid_atom_chars_regexp = re.compile("[()|@]")
 
 def isvalidatom(atom, allow_blockers=False):
@@ -585,10 +586,13 @@ def isvalidatom(atom, allow_blockers=False):
                return 0
        if allow_blockers and atom.startswith("!"):
                atom = atom[1:]
-       try:
-               mycpv_cps = catpkgsplit(dep_getcpv(atom))
-       except InvalidData:
-               return 0
+       cpv = dep_getcpv(atom)
+       if cpv:
+               if _valid_category.match(catsplit(cpv)[0]) is None:
+                       return 0
+               mycpv_cps = catpkgsplit(cpv)
+       else:
+               mycpv_cps = None
        operator = get_operator(atom)
        if operator:
                if operator[0] in "<>" and remove_slot(atom).endswith("*"):
index 512d9b4656005588d102589197c6e5991540ab8a..2b99b3dcb0b3f30375b799afa9458cbff2dbe608 100644 (file)
@@ -13,8 +13,7 @@ class IsValidAtom(TestCase):
        """
 
        def testIsValidAtom(self):
-       
-               self.todo = True        
+
                tests = [ ( "sys-apps/portage", True ),
                          ( "=sys-apps/portage-2.1", True ),
                          ( "=sys-apps/portage-2.1*", True ),
@@ -26,9 +25,10 @@ class IsValidAtom(TestCase):
                          ( "sys-apps/portage:foo", True ),
                          ( "sys-apps/portage-2.1:foo", False ),
                          ( "sys-apps/portage-2.1:", False ),
+                         ( "=sys-apps/portage-2.2*:foo[bar][-baz][doc?][-build?]", True ),
                          ( ">~cate-gory/foo-1.0", False ),
-                         ( ">~category/foo-1.0", True ),
-                         ( "<~category/foo-1.0", True ),
+                         ( ">~category/foo-1.0", False ),
+                         ( "<~category/foo-1.0", False ),
                          ( "###cat/foo-1.0", False ),
                          ( "~sys-apps/portage", False ),
                          ( "portage", False ) ]