| 6 | |
| 7 | |
| 8 | class TestConfigBox: |
| 9 | def test_config_box(self): |
| 10 | g = { |
| 11 | "b0": "no", |
| 12 | "b1": "yes", |
| 13 | "b2": "True", |
| 14 | "b3": "false", |
| 15 | "b4": True, |
| 16 | "i0": "34", |
| 17 | "f0": "5.5", |
| 18 | "f1": "3.333", |
| 19 | "l0": "4,5,6,7,8", |
| 20 | "l1": "[2 3 4 5 6]", |
| 21 | } |
| 22 | |
| 23 | cns = ConfigBox(bb=g) |
| 24 | assert cns.bb.list("l1", spliter=" ") == ["2", "3", "4", "5", "6"] |
| 25 | assert cns.bb.list("l0", mod=lambda x: int(x)) == [4, 5, 6, 7, 8] |
| 26 | assert not cns.bb.bool("b0") |
| 27 | assert cns.bb.bool("b1") |
| 28 | assert cns.bb.bool("b2") |
| 29 | assert not cns.bb.bool("b3") |
| 30 | assert cns.bb.int("i0") == 34 |
| 31 | assert cns.bb.float("f0") == 5.5 |
| 32 | assert cns.bb.float("f1") == 3.333 |
| 33 | assert cns.bb.getboolean("b4"), cns.bb.getboolean("b4") |
| 34 | assert cns.bb.getfloat("f0") == 5.5 |
| 35 | assert cns.bb.getint("i0") == 34 |
| 36 | assert cns.bb.getint("Hello!", 5) == 5 |
| 37 | assert cns.bb.getfloat("Wooo", 4.4) == 4.4 |
| 38 | assert cns.bb.getboolean("huh", True) is True |
| 39 | assert cns.bb.list("Waaaa", [1]) == [1] |
| 40 | assert repr(cns).startswith("ConfigBox(") |
| 41 | |
| 42 | def test_dir(self): |
| 43 | b = ConfigBox(test_dict) |
| 44 | |
| 45 | for item in ("to_yaml", "to_dict", "to_json", "int", "list", "float"): |
| 46 | assert item in dir(b) |
| 47 | |
| 48 | def test_config_default(self): |
| 49 | bx4 = Box(default_box=True, default_box_attr=ConfigBox) |
| 50 | assert isinstance(bx4.bbbbb, ConfigBox) |
nothing calls this directly
no outgoing calls
no test coverage detected