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
|
import textwrap
from unittest import mock
import pytest
from pkgcore.ebuild import domain as domain_mod
from pkgcore.ebuild import profiles
from pkgcore.fs.livefs import iter_scan
from pkgcore.restrictions import packages
from .test_profiles import profile_mixin
class TestDomain:
@pytest.fixture(autouse=True, scope="function")
def _setup(self, tmp_path_factory):
self.confdir = tmp_path_factory.mktemp("conf")
self.rootdir = tmp_path_factory.mktemp("root")
self.pmixin = profile_mixin()
self.profile_base = tmp_path_factory.mktemp("profiles")
self.profile1 = self.profile_base / "profile1"
self.pmixin.mk_profile(self.profile_base, str(self.profile1))
self.pusedir = self.confdir / "package.use"
self.pusedir.mkdir()
def mk_domain(self):
return domain_mod.domain(
profiles.OnDiskProfile(str(self.profile_base), "profile1"),
[],
[],
ROOT=self.rootdir,
config_dir=self.confdir,
)
def test_sorting(self):
"""assert that configuration files are read in alphanum ordering"""
# assert the base state; no files, no content.
assert () == self.mk_domain().pkg_use
(self.pusedir / "00").write_text("*/* X")
(self.pusedir / "01").write_text("*/* -X Y")
# Force the returned ordering to be reversed; this is to assert that
# the domain forces a sort.
orig_func = iter_scan
def rev_iter_scan(*args, **kwargs):
return iter(sorted(orig_func(*args, **kwargs), reverse=True))
with mock.patch(
"pkgcore.fs.livefs.iter_scan", side_effect=rev_iter_scan
), mock.patch("pkgcore.ebuild.domain.iter_scan", side_effect=rev_iter_scan):
assert (
(packages.AlwaysTrue, ((), ("X",))),
(packages.AlwaysTrue, (("X",), ("Y",))),
) == self.mk_domain().pkg_use
def test_use_expand_syntax(self):
(self.pusedir / "a").write_text(
"""
*/* x_y1
# unrelated is there to verify that it's unaffected by the USE_EXPAND
*/* unrelated X: -y1 y2
# multiple USE_EXPANDs
*/* unrelated X: -y1 y2 Z: -z3 z4
# cleanup previous
*/* x y -* z
# cleanup previous USE_EXPAND
*/* unrelated Y: y1 -* y2 Z: z1 -* -z2
"""
)
assert (
(packages.AlwaysTrue, ((), ("x_y1",))),
(
packages.AlwaysTrue,
(
("x_y1",),
(
"unrelated",
"x_y2",
),
),
),
(
packages.AlwaysTrue,
(
("x_y1", "z_z3"),
(
"unrelated",
"x_y2",
"z_z4",
),
),
),
(
packages.AlwaysTrue,
(
("*",),
("z",),
),
),
(
packages.AlwaysTrue,
(
(
"y_*",
"z_*",
"z_z2",
),
(
"unrelated",
"y_y2",
),
),
),
) == self.mk_domain().pkg_use
def test_use_flag_parsing_enforcement(self, caplog):
(self.pusedir / "a").write_text("*/* X:")
assert ((packages.AlwaysTrue, ((), ())),) == self.mk_domain().pkg_use
assert caplog.text == "" # no problems with nothing after USE_EXPAND:
caplog.clear()
(self.pusedir / "a").write_text("*/* y $x")
assert () == self.mk_domain().pkg_use
assert "token $x is not a valid use flag" in caplog.text
caplog.clear()
(self.pusedir / "a").write_text("*/* y X: $z")
assert () == self.mk_domain().pkg_use
assert "token x_$z is not a valid use flag" in caplog.text
caplog.clear()
|