diff options
author | Brian Harring <ferringb@gmail.com> | 2023-01-16 23:22:56 -0800 |
---|---|---|
committer | Arthur Zamarin <arthurzam@gentoo.org> | 2023-02-05 20:08:21 +0200 |
commit | 07602f09835ad21fed1603cd44923fe6e288c24a (patch) | |
tree | 607f266b4abaf220cdd9430fa95446e528535985 /tests/config | |
parent | refactor(config): remove indirection of multiplex.config_tree for multiplex.tree (diff) | |
download | pkgcore-07602f09835ad21fed1603cd44923fe6e288c24a.tar.gz pkgcore-07602f09835ad21fed1603cd44923fe6e288c24a.tar.bz2 pkgcore-07602f09835ad21fed1603cd44923fe6e288c24a.zip |
refactor(config): remove the notion of config layer incremental prepend/append.
Many moons gone past the original config system tried to support the idea
of incrementally stacked values (x y -x z -y == z). This commit removes
the fundamental core of that functionality; the incremental logic is now implemented
in domain specific layers, rather than being a capability of the config layer.
Note: this just removes the logic. The signature of [before, mid, after] return
is still in place, and will be removed as the API is normalized. In particular,
pconfig still reports on .prepend/.apend, there just no longer is content there.
That behaviour (and signature) change will be a followon commit.
Signed-off-by: Brian Harring <ferringb@gmail.com>
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
Diffstat (limited to 'tests/config')
-rw-r--r-- | tests/config/test_basics.py | 81 | ||||
-rw-r--r-- | tests/config/test_central.py | 86 | ||||
-rw-r--r-- | tests/config/test_cparser.py | 5 |
3 files changed, 2 insertions, 170 deletions
diff --git a/tests/config/test_basics.py b/tests/config/test_basics.py index e04cc704..10f0841e 100644 --- a/tests/config/test_basics.py +++ b/tests/config/test_basics.py @@ -248,87 +248,6 @@ class TestDictConfigSection: section.render_value(None, "list", "spoon") -class TestFakeIncrementalDictConfigSection: - @staticmethod - def _convert(central, value, arg_type): - return central, value, arg_type - - @staticmethod - def _fail(central, value, arg_type): - raise errors.ConfigurationError("fail") - - def test_misc(self): - section = basics.FakeIncrementalDictConfigSection( - self._convert, {"list": [1, 2]} - ) - assert "foo" not in section - assert "list" in section - assert ["list"] == list(section.keys()) - with pytest.raises(errors.ConfigurationError): - obj = basics.FakeIncrementalDictConfigSection(self._fail, {"a": "b"}) - obj.render_value(None, "a", "str") - - def test_fake_incrementals(self): - section = basics.FakeIncrementalDictConfigSection( - self._convert, {"seq.append": [1, 2]} - ) - manager = object() - assert [None, None, (manager, [1, 2], "list")] == section.render_value( - manager, "seq", "list" - ) - - def _repr(central, value, arg_type): - return "list", ["thing"] - - section = basics.FakeIncrementalDictConfigSection(_repr, {"foo": None}) - assert ("list", (None, ["thing"], None)) == section.render_value( - manager, "foo", "repr" - ) - with pytest.raises(errors.ConfigurationError): - obj = basics.FakeIncrementalDictConfigSection( - self._fail, {"a.prepend": "b"} - ) - obj.render_value(None, "a", "list") - - def test_repr(self): - def asis(central, value, arg_type): - assert arg_type == "repr", arg_type - return value - - source_dict = { - "seq.append": ("list", [1, 2]), - "simple": ("bool", True), - "multistr": ("str", "body"), - "multistr.prepend": ("str", "head"), - "refs": ("str", "lost"), - "refs.append": ("ref", "main"), - "refs.prepend": ("refs", ["a", "b"]), - "strlist": ("callable", asis), - "strlist.prepend": ("str", "whatever"), - "wrong.prepend": ("wrong", "wrong"), - } - section = basics.FakeIncrementalDictConfigSection(asis, source_dict) - manager = object() - with pytest.raises(KeyError): - section.render_value(manager, "spoon", "repr") - assert ("list", [None, None, [1, 2]]) == section.render_value( - manager, "seq", "repr" - ) - assert ("bool", True) == section.render_value(manager, "simple", "repr") - assert ("str", ["head", "body", None]) == section.render_value( - manager, "multistr", "repr" - ) - assert ("refs", [["a", "b"], ["lost"], ["main"]]) == section.render_value( - manager, "refs", "repr" - ) - assert ( - "list", - [["whatever"], ["tests.config.test_basics.asis"], None], - ) == section.render_value(manager, "strlist", "repr") - with pytest.raises(errors.ConfigurationError): - section.render_value(manager, "wrong", "repr") - - class TestConvertString: def test_render_value(self): source = { diff --git a/tests/config/test_central.py b/tests/config/test_central.py index 5ffb8072..55b541f8 100644 --- a/tests/config/test_central.py +++ b/tests/config/test_central.py @@ -970,89 +970,3 @@ def test_self_inherit(): ) assert manager.collapse_named_section("self") assert manager.collapse_section([section]) - - -def test_prepend_inherit(): - manager = central.ConfigManager( - [{"sect": basics.HardCodedConfigSection({"inherit.prepend": ["self"]})}] - ) - check_error( - "Collapsing section named 'sect':\n" - "Prepending or appending to the inherit list makes no sense", - manager.collapse_named_section, - "sect", - ) - - -def test_list_prepend(): - @configurable(types={"seq": "list"}) - def seq(seq): - return seq - - manager = central.ConfigManager( - [ - { - "inh": basics.HardCodedConfigSection( - { - "inherit": ["sect"], - "seq.prepend": ["pre"], - } - ), - "sect": basics.HardCodedConfigSection( - { - "inherit": ["base"], - "seq": ["1", "2"], - } - ), - }, - { - "base": basics.HardCodedConfigSection( - { - "class": seq, - "seq.prepend": ["-1"], - "seq.append": ["post"], - } - ) - }, - ] - ) - assert ["-1", "post"] == manager.objects.seq["base"] - assert ["1", "2"] == manager.objects.seq["sect"] - assert ["pre", "1", "2"] == manager.objects.seq["inh"] - - -def test_str_prepend(): - @configurable(types={"string": "str"}) - def sect(string): - return string - - manager = central.ConfigManager( - [ - { - "inh": basics.HardCodedConfigSection( - { - "inherit": ["sect"], - "string.prepend": "pre", - } - ), - "sect": basics.HardCodedConfigSection( - { - "inherit": ["base"], - "string": "b", - } - ), - }, - { - "base": basics.HardCodedConfigSection( - { - "class": sect, - "string.prepend": "a", - "string.append": "c", - } - ) - }, - ] - ) - assert "a c" == manager.objects.sect["base"] - assert "b" == manager.objects.sect["sect"] - assert "pre b" == manager.objects.sect["inh"] diff --git a/tests/config/test_cparser.py b/tests/config/test_cparser.py index e7d0b0ea..a9082adb 100644 --- a/tests/config/test_cparser.py +++ b/tests/config/test_cparser.py @@ -2,6 +2,7 @@ import textwrap from io import StringIO import pytest + from pkgcore.config import central, cparser, errors @@ -33,8 +34,6 @@ class TestConfigFromIni: [test] string = 'hi I am a string' list = foo bar baz - list.prepend = pre bits - list.append = post bits true = yes false = no """ @@ -48,7 +47,7 @@ class TestConfigFromIni: ( "list", "list", - [["pre", "bits"], ["foo", "bar", "baz"], ["post", "bits"]], + [None, ["foo", "bar", "baz"], None], ), ("true", "bool", True), ("false", "bool", False), |