MCPcopy Create free account
hub / github.com/cdgriffith/Box / TestConfigBoxCaseInsensitive

Class TestConfigBoxCaseInsensitive

test/test_config_box_case.py:14–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class TestConfigBoxCaseInsensitive:
15 @pytest.mark.parametrize("outer", [list, iter])
16 def test_merge_update_one_shot_pairs(self, outer):
17 cb = ConfigBox({"Host": {"port": 80}})
18 pairs = outer([iter(("host", {"name": "localhost"})), iter(("timeout", 30))])
19 cb.merge_update(pairs)
20 assert cb.to_dict() == {"host": {"port": 80, "name": "localhost"}, "timeout": 30}
21 assert list(cb) == ["host", "timeout"]
22 assert cb.HOST.port == 80
23
24 def test_lookup_any_case(self):
25 cb = ConfigBox({"HOST": "localhost", "ServerPort": 8080})
26 assert cb["host"] == cb["Host"] == cb.host == cb.HOST == "localhost"
27 assert cb.serverport == cb["SERVERPORT"] == 8080
28 assert "host" in cb and "serverPORT" in cb and "nope" not in cb
29 assert cb.get("host") == "localhost"
30 assert cb.get("nope", 5) == 5
31
32 def test_transforms_any_case(self):
33 cb = ConfigBox({"Flag": "yes", "Count": "5", "Ratio": "1.5", "Items": "a, b"})
34 assert cb.bool("flag") is True
35 assert cb.int("COUNT") == 5
36 assert cb.getfloat("ratio") == 1.5
37 assert cb.list("items") == ["a", "b"]
38
39 def test_latest_write_wins_on_construction(self):
40 assert ConfigBox({"Foo": 1, "foo": 2}).to_dict() == {"foo": 2}
41 assert ConfigBox({"Foo": 1, "foo": 2, "FOO": 3}).to_dict() == {"FOO": 3}
42 assert ConfigBox(A=1, a=2).to_dict() == {"a": 2}
43 assert ConfigBox.from_json('{"Foo": 1, "foo": 2}').to_dict() == {"foo": 2}
44
45 def test_latest_write_wins_on_assignment(self):
46 cb = ConfigBox({"host": "a", "port": 1})
47 cb["HOST"] = "b"
48 assert cb.to_dict() == {"port": 1, "HOST": "b"}
49 cb.Host = "c"
50 assert cb.to_dict() == {"port": 1, "Host": "c"}
51 cb.Host = "d" # same spelling replaces in place
52 assert list(cb.keys()) == ["port", "Host"]
53 assert cb.host == "d"
54
55 def test_update_and_merge_update_agree(self):
56 for method in ("update", "merge_update"):
57 cb = ConfigBox({"Host": "h", "port": 1})
58 getattr(cb, method)({"HOST": "u"})
59 assert cb.to_dict() == {"port": 1, "HOST": "u"}, method
60 getattr(cb, method)(host="v")
61 assert cb.to_dict() == {"port": 1, "host": "v"}, method
62 getattr(cb, method)([("Host", "w")])
63 assert cb.to_dict() == {"port": 1, "Host": "w"}, method
64 cb = ConfigBox()
65 cb.update({"a": 1, "A": 2})
66 assert cb.to_dict() == {"A": 2}
67
68 def test_merge_update_merges_nested_and_takes_spelling(self):
69 cb = ConfigBox({"Server": {"host": "h", "port": 1}})
70 cb.merge_update({"SERVER": {"PORT": 2}})
71 assert cb.to_dict() == {"SERVER": {"host": "h", "PORT": 2}}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected