1 # Copyright 2010-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 from portage.tests import TestCase
5 from portage.dep import extract_affecting_use
6 from portage.exception import InvalidDependString
8 class TestExtractAffectingUSE(TestCase):
10 def testExtractAffectingUSE(self):
12 ("a? ( A ) !b? ( B ) !c? ( C ) d? ( D )", "A", ("a",)),
13 ("a? ( A ) !b? ( B ) !c? ( C ) d? ( D )", "B", ("b",)),
14 ("a? ( A ) !b? ( B ) !c? ( C ) d? ( D )", "C", ("c",)),
15 ("a? ( A ) !b? ( B ) !c? ( C ) d? ( D )", "D", ("d",)),
17 ("a? ( b? ( AB ) )", "AB", ("a", "b")),
18 ("a? ( b? ( c? ( ABC ) ) )", "ABC", ("a", "b", "c")),
20 ("a? ( A b? ( c? ( ABC ) AB ) )", "A", ("a",)),
21 ("a? ( A b? ( c? ( ABC ) AB ) )", "AB", ("a", "b")),
22 ("a? ( A b? ( c? ( ABC ) AB ) )", "ABC", ("a", "b", "c")),
23 ("a? ( A b? ( c? ( ABC ) AB ) ) X", "X", []),
24 ("X a? ( A b? ( c? ( ABC ) AB ) )", "X", []),
26 ("ab? ( || ( A B ) )", "A", ("ab",)),
27 ("!ab? ( || ( A B ) )", "B", ("ab",)),
28 ("ab? ( || ( A || ( b? ( || ( B C ) ) ) ) )", "A", ("ab",)),
29 ("ab? ( || ( A || ( b? ( || ( B C ) ) ) ) )", "B", ("ab", "b")),
30 ("ab? ( || ( A || ( b? ( || ( B C ) ) ) ) )", "C", ("ab", "b")),
32 ("( ab? ( || ( ( A ) || ( b? ( ( ( || ( B ( C ) ) ) ) ) ) ) ) )", "A", ("ab",)),
33 ("( ab? ( || ( ( A ) || ( b? ( ( ( || ( B ( C ) ) ) ) ) ) ) ) )", "B", ("ab", "b")),
34 ("( ab? ( || ( ( A ) || ( b? ( ( ( || ( B ( C ) ) ) ) ) ) ) ) )", "C", ("ab", "b")),
36 ("a? ( A )", "B", []),
38 ("a? ( || ( A B ) )", "B", ["a"]),
40 # test USE dep defaults for bug #363073
41 ("a? ( >=dev-lang/php-5.2[pcre(+)] )", ">=dev-lang/php-5.2[pcre(+)]", ["a"]),
56 ("|| ( A B ) )", "A"),
58 ("|| ( A B || )", "A"),
60 ("( || ( || || ( A ) foo? ( B ) ) )", "A"),
61 ("( || ( || bar? ( A ) foo? ( B ) ) )", "A"),
64 for dep, atom, expected in test_cases:
65 expected = set(expected)
66 result = extract_affecting_use(dep, atom)
67 fail_msg = "dep: " + dep + ", atom: " + atom + ", got: " + \
68 " ".join(sorted(result)) + ", expected: " + " ".join(sorted(expected))
69 self.assertEqual(result, expected, fail_msg)
71 for dep, atom in test_cases_xfail:
72 fail_msg = "dep: " + dep + ", atom: " + atom + ", got: " + \
73 " ".join(sorted(result)) + ", expected: " + " ".join(sorted(expected))
74 self.assertRaisesMsg(fail_msg, \
75 InvalidDependString, extract_affecting_use, dep, atom)