1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage.tests import TestCase
from portage.dep import check_required_use
from portage.exception import InvalidDependString
class TestCheckRequiredUse(TestCase):
def testCheckRequiredUse(self):
test_cases = (
( "|| ( a b )", [], ["a", "b"], False),
( "|| ( a b )", ["a"], ["a", "b"], True),
( "|| ( a b )", ["b"], ["a", "b"], True),
( "|| ( a b )", ["a", "b"], ["a", "b"], True),
( "^^ ( a b )", [], ["a", "b"], False),
( "^^ ( a b )", ["a"], ["a", "b"], True),
( "^^ ( a b )", ["b"], ["a", "b"], True),
( "^^ ( a b )", ["a", "b"], ["a", "b"], False),
( "^^ ( || ( a b ) c )", [], ["a", "b", "c"], False),
( "^^ ( || ( a b ) c )", ["a"], ["a", "b", "c"], True),
( "^^ ( || ( ( a b ) ) ( c ) )", [], ["a", "b", "c"], False),
( "( ^^ ( ( || ( ( a ) ( b ) ) ) ( ( c ) ) ) )", ["a"], ["a", "b", "c"], True),
( "a || ( b c )", ["a"], ["a", "b", "c"], False),
( "|| ( b c ) a", ["a"], ["a", "b", "c"], False),
( "|| ( a b c )", ["a"], ["a", "b", "c"], True),
( "|| ( a b c )", ["b"], ["a", "b", "c"], True),
( "|| ( a b c )", ["c"], ["a", "b", "c"], True),
( "^^ ( a b c )", ["a"], ["a", "b", "c"], True),
( "^^ ( a b c )", ["b"], ["a", "b", "c"], True),
( "^^ ( a b c )", ["c"], ["a", "b", "c"], True),
( "^^ ( a b c )", ["a", "b"], ["a", "b", "c"], False),
( "^^ ( a b c )", ["b", "c"], ["a", "b", "c"], False),
( "^^ ( a b c )", ["a", "c"], ["a", "b", "c"], False),
( "^^ ( a b c )", ["a", "b", "c"], ["a", "b", "c"], False),
( "a? ( ^^ ( b c ) )", [], ["a", "b", "c"], True),
( "a? ( ^^ ( b c ) )", ["a"], ["a", "b", "c"], False),
( "a? ( ^^ ( b c ) )", ["b"], ["a", "b", "c"], True),
( "a? ( ^^ ( b c ) )", ["c"], ["a", "b", "c"], True),
( "a? ( ^^ ( b c ) )", ["a", "b"], ["a", "b", "c"], True),
( "a? ( ^^ ( b c ) )", ["a", "b", "c"], ["a", "b", "c"], False),
( "^^ ( a? ( !b ) !c? ( d ) )", [], ["a", "b", "c", "d"], False),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a"], ["a", "b", "c", "d"], True),
( "^^ ( a? ( !b ) !c? ( d ) )", ["c"], ["a", "b", "c", "d"], True),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a", "c"], ["a", "b", "c", "d"], True),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a", "b", "c"], ["a", "b", "c", "d"], False),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a", "b", "d"], ["a", "b", "c", "d"], True),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a", "b", "d"], ["a", "b", "c", "d"], True),
( "^^ ( a? ( !b ) !c? ( d ) )", ["a", "d"], ["a", "b", "c", "d"], False),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", [], ["a", "b", "c"], False),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["a"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["b"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["c"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["a", "b"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["a", "c"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["b", "c"], ["a", "b", "c"], True),
( "|| ( ^^ ( a b ) ^^ ( b c ) )", ["a", "b", "c"], ["a", "b", "c"], False),
( "^^ ( || ( a b ) ^^ ( b c ) )", [], ["a", "b", "c"], False),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["a"], ["a", "b", "c"], True),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["b"], ["a", "b", "c"], False),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["c"], ["a", "b", "c"], True),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["a", "b"], ["a", "b", "c"], False),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["a", "c"], ["a", "b", "c"], False),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["b", "c"], ["a", "b", "c"], True),
( "^^ ( || ( a b ) ^^ ( b c ) )", ["a", "b", "c"], ["a", "b", "c"], True),
)
test_cases_xfail = (
( "^^ ( || ( a b ) ^^ ( b c ) )", [], ["a", "b"]),
( "^^ ( || ( a b ) ^^ ( b c )", [], ["a", "b", "c"]),
( "^^( || ( a b ) ^^ ( b c ) )", [], ["a", "b", "c"]),
( "^^ || ( a b ) ^^ ( b c )", [], ["a", "b", "c"]),
( "^^ ( ( || ) ( a b ) ^^ ( b c ) )", [], ["a", "b", "c"]),
( "^^ ( || ( a b ) ) ^^ ( b c ) )", [], ["a", "b", "c"]),
)
for required_use, use, iuse, expected in test_cases:
self.assertEqual(check_required_use(required_use, use, iuse.__contains__), \
expected, required_use + ", USE = " + " ".join(use))
for required_use, use, iuse in test_cases_xfail:
self.assertRaisesMsg(required_use + ", USE = " + " ".join(use), \
InvalidDependString, check_required_use, required_use, use, iuse.__contains__)
|