From f465f3a21c4e814885d53ce29c7e6e4ab38db16f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Fri, 4 Feb 2011 13:07:52 -0800 Subject: REQUIRED_USE: fix parens display and test more --- pym/portage/dep/__init__.py | 44 +++++++++++++++++++-------- pym/portage/tests/dep/testCheckRequiredUse.py | 5 +++ 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py index 62e96d29a..b27d58956 100644 --- a/pym/portage/dep/__init__.py +++ b/pym/portage/dep/__init__.py @@ -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 diff --git a/pym/portage/tests/dep/testCheckRequiredUse.py b/pym/portage/tests/dep/testCheckRequiredUse.py index 332c5a5df..c5a8f5304 100644 --- a/pym/portage/tests/dep/testCheckRequiredUse.py +++ b/pym/portage/tests/dep/testCheckRequiredUse.py @@ -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: -- cgit v1.2.3-1-g7c22