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

Class TestConfigBox

test/test_edge_cases.py:767–844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

765
766
767class TestConfigBox:
768 def test_bool_transform_values_defaults_and_missing(self):
769 cfg = ConfigBox(yes="yes", no="No", f="F", zero="0", one="1", false="FALSE", empty="", real=False, num=0, two=2)
770 for name in ("yes", "one", "two"):
771 assert cfg.bool(name) is True
772 for name in ("no", "f", "zero", "false", "empty", "real", "num"):
773 assert cfg.bool(name) is False
774 assert cfg.bool("missing", True) is True
775 assert cfg.bool("missing", False) is False
776 assert cfg.getboolean("YES") is True
777 with pytest.raises(BoxKeyError):
778 cfg.bool("missing")
779
780 def test_list_transform_options(self):
781 cfg = ConfigBox(a=" 1, 2 ,3 ", b="[x;y]", c="5")
782 assert cfg.list("a") == ["1", "2", "3"]
783 assert cfg.list("a", mod=int) == [1, 2, 3]
784 assert cfg.list("a", strip=False) == [" 1", " 2 ", "3 "]
785 assert cfg.list("b", spliter=";") == ["x", "y"]
786 assert cfg.list("c") == ["5"]
787 assert cfg.list("missing", default=["d"]) == ["d"]
788 with pytest.raises(BoxKeyError):
789 cfg.list("missing")
790
791 def test_case_insensitive_with_nested_boxes_and_box_dots(self):
792 cfg = ConfigBox({"Server": {"Port": "80", "Hosts": {"Main": "a"}}}, box_dots=True)
793 assert cfg.server.port == "80"
794 assert cfg["SERVER"]["port"] == "80"
795 assert cfg["server.port"] == "80"
796 assert cfg["SERVER.hosts.MAIN"] == "a"
797 assert "server.hosts.main" in cfg
798 assert cfg.int("server.port", 0) in (80, 0)
799 cfg["SERVER.Port"] = "81"
800 assert cfg == {"Server": {"Port": "81", "Hosts": {"Main": "a"}}}
801 assert type(cfg.server.hosts) is ConfigBox
802 del cfg["server.HOSTS.main"]
803 assert cfg.Server.Hosts == {}
804
805 def test_latest_write_wins_for_every_write_path(self):
806 cfg = ConfigBox({"Foo": 1})
807 cfg["FOO"] = 2
808 assert list(cfg.items()) == [("FOO", 2)]
809 cfg.update(foo=3)
810 assert list(cfg.items()) == [("foo", 3)]
811 cfg.merge_update({"Foo": 4})
812 assert list(cfg.items()) == [("Foo", 4)]
813 cfg.other = 1
814 cfg.FOO = 5
815 assert list(cfg.items()) == [("other", 1), ("FOO", 5)]
816 assert ConfigBox([("a", 1), ("A", 2)]) == {"A": 2}
817
818 def test_default_box_and_ephemeral_children_ignore_case(self):
819 cfg = ConfigBox(default_box=True)
820 cfg.Sec.a = 1
821 cfg.SEC.b = 2
822 cfg.sec["c"] = 3
823 assert cfg == {"Sec": {"a": 1, "b": 2, "c": 3}}
824 stale = cfg.Other

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected