Update timestamps in headers of modified files.
[portage.git] / pym / portage / tests / dep / testExtractAffectingUSE.py
1 # Copyright 2010-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 from portage.tests import TestCase
5 from portage.dep import extract_affecting_use
6 from portage.exception import InvalidDependString
7
8 class TestExtractAffectingUSE(TestCase):
9
10         def testExtractAffectingUSE(self):
11                 test_cases = (
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",)),
16                         
17                         ("a? ( b? ( AB ) )", "AB", ("a", "b")),
18                         ("a? ( b? ( c? ( ABC ) ) )", "ABC", ("a", "b", "c")),
19
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", []),
25
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")),
31
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")),
35
36                         ("a? ( A )", "B", []),
37
38                         ("a? ( || ( A B ) )", "B", ["a"]),
39
40                         # test USE dep defaults for bug #363073
41                         ("a? ( >=dev-lang/php-5.2[pcre(+)] )", ">=dev-lang/php-5.2[pcre(+)]", ["a"]),
42                 )
43
44                 test_cases_xfail = (
45                         ("? ( A )", "A"),
46                         ("!? ( A )", "A"),
47                         ("( A", "A"),
48                         ("A )", "A"),
49                         
50                         ("||( A B )", "A"),
51                         ("|| (A B )", "A"),
52                         ("|| ( A B)", "A"),
53                         ("|| ( A B", "A"),
54                         ("|| A B )", "A"),
55                         ("|| A B", "A"),
56                         ("|| ( A B ) )", "A"),
57                         ("|| || B C", "A"),
58                         ("|| ( A B || )", "A"),
59                         ("a? A", "A"),
60                         ("( || ( || || ( A ) foo? ( B ) ) )", "A"),
61                         ("( || ( || bar? ( A ) foo? ( B ) ) )", "A"),
62                 )
63
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)
70
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)