Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Force stable sorting of /etc/portage/* files loading.
Specifically, alphanumeric sorting; a '00' should always be parsed before an '01' or 'a'. The ordering must be stable so that globals- in a 00 file- can be overridden per package via other files. If there is no stable ordering forced on how the order of files read, then this isn't supported. Closes: #385 Signed-off-by: Brian Harring <ferringb@gmail.com> Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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)) | ||
|
||
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""" | ||
cdir = self.confdir / "package.use" | ||
cdir.mkdir() | ||
|
||
# assert the base state; no files, no content. | ||
assert () == self.mk_domain().pkg_use | ||
|
||
open(cdir / "00", "w").write("*/* X") | ||
open(cdir / "01", "w").write("*/* -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 |