REQUIRED_USE: fix parens display and test more
authorZac Medico <zmedico@gentoo.org>
Fri, 4 Feb 2011 21:07:52 +0000 (13:07 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 4 Feb 2011 21:07:52 +0000 (13:07 -0800)
pym/portage/dep/__init__.py
pym/portage/tests/dep/testCheckRequiredUse.py

index 62e96d29a9aaeaa4ff8489aeee52ed0c634cc5c2..b27d589561ccf29c39891f16d1f0f719cdfb5a6c 100644 (file)
@@ -1,5 +1,5 @@
 # deps.py -- Portage dependency resolution functions
-# Copyright 2003-2010 Gentoo Foundation
+# Copyright 2003-2011 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = [
@@ -2206,7 +2206,10 @@ def check_required_use(required_use, use, iuse_match):
                                                else:
                                                        stack[level].pop()
                                                        node._satisfied = True
-                                                       node._parent._children.remove(node)
+                                                       last_node = node._parent._children.pop()
+                                                       if last_node is not node:
+                                                               raise AssertionError(
+                                                                       "node is not last child of parent")
                                                        node = node._parent
                                                        continue
                                                ignore = True
@@ -2216,20 +2219,28 @@ def check_required_use(required_use, use, iuse_match):
                                        stack[level].append(satisfied)
                                        node._satisfied = satisfied
                                        if node._parent._operator not in ("||", "^^"):
-                                               offset = node._parent._children.index(node)
-                                               node._parent._children.pop(offset)
-                                               for i, child in enumerate(node._children):
-                                                       node._parent._children.insert(offset + i, child)
+                                               last_node = node._parent._children.pop()
+                                               if last_node is not node:
+                                                       raise AssertionError(
+                                                               "node is not last child of parent")
+                                               for child in node._children:
+                                                       node._parent._children.append(child)
                                                        if isinstance(child, _RequiredUseBranch):
                                                                child._parent = node._parent
                                        node = node._parent
                                        continue
 
                                if not node._children:
-                                       node._parent._children.remove(node)
+                                       last_node = node._parent._children.pop()
+                                       if last_node is not node:
+                                               raise AssertionError(
+                                                       "node is not last child of parent")
                                elif len(node._children) == 1:
-                                       index = node._parent._children.index(node)
-                                       node._parent._children[index] = node._children[0]
+                                       last_node = node._parent._children.pop()
+                                       if last_node is not node:
+                                               raise AssertionError(
+                                                       "node is not last child of parent")
+                                       node._parent._children.append(node._children[0])
                                        if isinstance(node._children[0], _RequiredUseBranch):
                                                node._children[0]._parent = node._parent
                                                node = node._children[0]
@@ -2238,10 +2249,10 @@ def check_required_use(required_use, use, iuse_match):
                                                if isinstance(child, _RequiredUseBranch) and \
                                                        child._operator is None and \
                                                        len(child._children) == 1:
-                                                       node._children[index] = child._children[0]
-                                                       if isinstance(node._children[index],
-                                                               _RequiredUseBranch):
-                                                               node._children[index]._parent = node
+                                                       child = child._children[0]
+                                                       node._children[index] = child
+                                                       if isinstance(child, _RequiredUseBranch):
+                                                               child._parent = node
 
                                node = node._parent
                        else:
@@ -2277,6 +2288,13 @@ def check_required_use(required_use, use, iuse_match):
                raise InvalidDependString(
                        _("malformed syntax: '%s'") % required_use)
 
+       if len(tree._children) == 1:
+               child = tree._children[0]
+               if isinstance(child, _RequiredUseBranch) and \
+                       child._operator is None:
+                       tree = child
+                       tree._parent = None
+
        tree._satisfied = False not in stack[0]
        return tree
 
index 332c5a5df9d108dc670fc79ca5234c7ed33e4943..c5a8f530453522a2b92e6d7a7430e46713b288b2 100644 (file)
@@ -190,6 +190,11 @@ class TestCheckRequiredUse(TestCase):
                                "^^ ( ( a b c ) ( b c !d ) )",
                                ["a", "b", "c", "d"],
                                ""
+                       ),
+                       (
+                               "|| ( ( ( ( a ) ) ( ( ( b c ) ) ) ) )",
+                               [""],
+                               "a b c"
                        )
                )
                for required_use, use, expected in test_cases: