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

index 7e9a18ad3392896059a612d17523bfeb3b033971..0300b748996e41276ae568135f0e93080f30e91b 100644 (file)
@@ -2088,11 +2088,14 @@ class _RequiredUseBranch(object):
 
        def tounicode(self):
 
+               include_parens = self._parent is not None and \
+                       (self._operator is not None or \
+                       self._parent._operator is None)
                tokens = []
                if self._operator is not None:
                        tokens.append(self._operator)
 
-               if self._parent is not None:
+               if include_parens:
                        tokens.append("(")
 
                complex_nesting = False
@@ -2111,7 +2114,7 @@ class _RequiredUseBranch(object):
                                if not child._satisfied:
                                        tokens.append(child.tounicode())
 
-               if self._parent is not None:
+               if include_parens:
                        tokens.append(")")
 
                return " ".join(tokens)
index 0f7a299e9015022461fe0e2698331dc8009b588b..0fb97023a70e32de48ed5ec1b6fa58e48a6f0a37 100644 (file)
@@ -134,7 +134,37 @@ class TestCheckRequiredUse(TestCase):
                        (
                                "^^ ( || ( ( a b ) ) ( c ) )",
                                ("a", "b", "c"),
-                               "^^ ( || ( ( a b ) ) ( c ) )"
+                               "^^ ( || ( a b ) c )"
+                       ),
+                       (
+                               "a? ( ( c e ) ( b d ) )",
+                               ("a", "c", "e"),
+                               "a? ( b d )"
+                       ),
+                       (
+                               "a? ( ( c e ) ( b d ) )",
+                               ("a", "b", "c", "e"),
+                               "a? ( d )"
+                       ),
+                       (
+                               "^^ ( || ( a b ) ^^ ( b c ) )",
+                               ("a", "b"),
+                               "^^ ( || ( a b ) ^^ ( b c ) )"
+                       ),
+                       (
+                               "^^ ( || ( a b ) ^^ ( b c ) )",
+                               ["a", "c"],
+                               "^^ ( || ( a b ) ^^ ( b c ) )"
+                       ),
+                       (
+                               "^^ ( || ( a b ) ^^ ( b c ) )",
+                               ["b", "c"],
+                               ""
+                       ),
+                       (
+                               "^^ ( || ( a b ) ^^ ( b c ) )",
+                               ["a", "b", "c"],
+                               ""
                        )
                )
                for required_use, use, expected in test_cases: