| 8 | |
| 9 | |
| 10 | class TestDotsIntegerKeys: |
| 11 | def test_lookup(self): |
| 12 | info = Box({"uno": {2: "tres", "cuatro": 5}}, default_box=True, box_dots=True) |
| 13 | assert info["uno.2"] == "tres" |
| 14 | assert info["uno.cuatro"] == 5 |
| 15 | assert "uno.2" in info |
| 16 | assert "uno.3" not in info |
| 17 | |
| 18 | def test_first_segment_and_negative(self): |
| 19 | b = Box({1: {"a": "x"}, "n": {-1: "neg"}}, box_dots=True) |
| 20 | assert b["1.a"] == "x" |
| 21 | assert b["n.-1"] == "neg" |
| 22 | assert "1.a" in b |
| 23 | |
| 24 | def test_plain_keys_are_not_mapped(self): |
| 25 | b = Box({2: "int"}, box_dots=True) |
| 26 | with pytest.raises(BoxKeyError): |
| 27 | b["2"] |
| 28 | assert "2" not in b |
| 29 | b["2"] = "str" |
| 30 | assert b.to_dict() == {2: "int", "2": "str"} |
| 31 | |
| 32 | def test_string_key_still_wins(self): |
| 33 | b = Box({"uno": {2: "int", "2": "str"}}, box_dots=True) |
| 34 | assert b["uno.2"] == "str" |
| 35 | assert b.uno[2] == "int" |
| 36 | |
| 37 | def test_set_and_delete_update_the_int_key(self): |
| 38 | b = Box({"uno": {2: "tres"}}, box_dots=True) |
| 39 | b["uno.2"] = "dos" |
| 40 | assert b.to_dict() == {"uno": {2: "dos"}} |
| 41 | del b["uno.2"] |
| 42 | assert b.to_dict() == {"uno": {}} |
| 43 | |
| 44 | def test_missing_still_missing(self): |
| 45 | b = Box({"uno": {2: "tres"}}, box_dots=True) |
| 46 | with pytest.raises(BoxKeyError): |
| 47 | b["uno.3"] |
| 48 | b2 = Box({"uno": {}}, box_dots=True, default_box=True) |
| 49 | assert b2["uno.3"] == Box() |
| 50 | |
| 51 | def test_not_digits_or_without_box_dots(self): |
| 52 | b = Box({"uno": {2: "tres", 1.5: "float"}}, box_dots=True) |
| 53 | with pytest.raises(BoxKeyError): |
| 54 | b["uno.²"] # a unicode digit, not an int |
| 55 | with pytest.raises(BoxKeyError): |
| 56 | Box({2: "tres"})["2"] |
| 57 | |
| 58 | def test_box_list_index_unchanged(self): |
| 59 | b = Box({"items": [{"a": 1}, {"a": 2}]}, box_dots=True) |
| 60 | assert b["items[1].a"] == 2 |
| 61 | |
| 62 | |
| 63 | class TestCamelKillerKeepKeys: |
nothing calls this directly
no outgoing calls
no test coverage detected