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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
import portage
from portage import os
from portage.package.ebuild.config import config
from portage.package.ebuild._config.LicenseManager import LicenseManager
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground, ResolverPlaygroundTestCase
class ConfigTestCase(TestCase):
def testFeaturesMutation(self):
"""
Test whether mutation of config.features updates the FEATURES
variable and persists through config.regenerate() calls. Also
verify that features_set._prune_overrides() works correctly.
"""
playground = ResolverPlayground()
try:
settings = config(clone=playground.settings)
settings.features.add('noclean')
self.assertEqual('noclean' in settings['FEATURES'].split(), True)
settings.regenerate()
self.assertEqual('noclean' in settings['FEATURES'].split(),True)
settings.features.discard('noclean')
self.assertEqual('noclean' in settings['FEATURES'].split(), False)
settings.regenerate()
self.assertEqual('noclean' in settings['FEATURES'].split(), False)
settings.features.add('noclean')
self.assertEqual('noclean' in settings['FEATURES'].split(), True)
settings.regenerate()
self.assertEqual('noclean' in settings['FEATURES'].split(),True)
# before: ['noclean', '-noclean', 'noclean']
settings.features._prune_overrides()
# after: ['noclean']
self.assertEqual(settings._features_overrides.count('noclean'), 1)
self.assertEqual(settings._features_overrides.count('-noclean'), 0)
settings.features.remove('noclean')
# before: ['noclean', '-noclean']
settings.features._prune_overrides()
# after: ['-noclean']
self.assertEqual(settings._features_overrides.count('noclean'), 0)
self.assertEqual(settings._features_overrides.count('-noclean'), 1)
finally:
playground.cleanup()
def testLicenseManager(self):
user_config = {
"package.license":
(
"dev-libs/* TEST",
"dev-libs/A -TEST2",
"=dev-libs/A-2 TEST3 @TEST",
"*/* @EULA TEST2",
"=dev-libs/C-1 *",
"=dev-libs/C-2 -*",
),
}
playground = ResolverPlayground(user_config=user_config)
try:
portage.util.noiselimit = -2
license_group_locations = (os.path.join(playground.portdir, "profiles"),)
pkg_license = os.path.join(playground.eroot, "etc", "portage")
lic_man = LicenseManager(license_group_locations, pkg_license)
self.assertEqual(lic_man._accept_license_str, None)
self.assertEqual(lic_man._accept_license, None)
self.assertEqual(lic_man._license_groups, {"EULA": ["TEST"]})
self.assertEqual(lic_man._undef_lic_groups, set(["TEST"]))
self.assertEqual(lic_man.extract_global_changes(), "TEST TEST2")
self.assertEqual(lic_man.extract_global_changes(), "")
lic_man.set_accept_license_str("TEST TEST2")
self.assertEqual(lic_man._getPkgAcceptLicense("dev-libs/B-1", "0"), ["TEST", "TEST2", "TEST"])
self.assertEqual(lic_man._getPkgAcceptLicense("dev-libs/A-1", "0"), ["TEST", "TEST2", "TEST", "-TEST2"])
self.assertEqual(lic_man._getPkgAcceptLicense("dev-libs/A-2", "0"), ["TEST", "TEST2", "TEST", "-TEST2", "TEST3", "@TEST"])
self.assertEqual(lic_man.get_prunned_accept_license("dev-libs/B-1", [], "TEST", "0"), "TEST")
self.assertEqual(lic_man.get_prunned_accept_license("dev-libs/A-1", [], "-TEST2", "0"), "")
self.assertEqual(lic_man.get_prunned_accept_license("dev-libs/A-2", [], "|| ( TEST TEST2 )", "0"), "TEST")
self.assertEqual(lic_man.get_prunned_accept_license("dev-libs/C-1", [], "TEST5", "0"), "TEST5")
self.assertEqual(lic_man.get_prunned_accept_license("dev-libs/C-2", [], "TEST2", "0"), "")
self.assertEqual(lic_man.getMissingLicenses("dev-libs/B-1", [], "TEST", "0"), [])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/A-1", [], "-TEST2", "0"), ["-TEST2"])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/A-2", [], "|| ( TEST TEST2 )", "0"), [])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/A-3", [], "|| ( TEST2 || ( TEST3 TEST4 ) )", "0"), ["TEST2", "TEST3", "TEST4"])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/C-1", [], "TEST5", "0"), [])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/C-2", [], "TEST2", "0"), ["TEST2"])
self.assertEqual(lic_man.getMissingLicenses("dev-libs/D-1", [], "", "0"), [])
finally:
portage.util.noiselimit = 0
playground.cleanup()
def testPackageMaskOrder(self):
ebuilds = {
"dev-libs/A-1": { },
"dev-libs/B-1": { },
"dev-libs/C-1": { },
"dev-libs/D-1": { },
"dev-libs/E-1": { },
}
repo_config = {
"package.mask":
(
"dev-libs/A",
"dev-libs/C",
),
}
profile = {
"package.mask":
(
"-dev-libs/A",
"dev-libs/B",
"-dev-libs/B",
"dev-libs/D",
),
}
user_config = {
"package.mask":
(
"-dev-libs/C",
"-dev-libs/D",
"dev-libs/E",
),
}
test_cases = (
ResolverPlaygroundTestCase(
["dev-libs/A"],
success = False),
ResolverPlaygroundTestCase(
["dev-libs/B"],
success = True,
mergelist = ["dev-libs/B-1"]),
ResolverPlaygroundTestCase(
["dev-libs/C"],
success = True,
mergelist = ["dev-libs/C-1"]),
ResolverPlaygroundTestCase(
["dev-libs/D"],
success = True,
mergelist = ["dev-libs/D-1"]),
ResolverPlaygroundTestCase(
["dev-libs/E"],
success = False),
)
playground = ResolverPlayground(ebuilds=ebuilds, repo_config=repo_config, \
profile=profile, user_config=user_config)
try:
for test_case in test_cases:
playground.run_TestCase(test_case)
self.assertEqual(test_case.test_success, True, test_case.fail_msg)
finally:
playground.cleanup()
|