Ejemplo n.º 1
0
    def test_box_dots(self):
        b = Box(
            {"my_key": {"does stuff": {"to get to": "where I want"}}, "key.with.list": [[[{"test": "value"}]]]},
            box_dots=True,
        )
        for key in b.keys(dotted=True):
            b[key]

        c = Box(extended_test_dict.copy(), box_dots=True)
        for key in c.keys(dotted=True):
            c[key]

        assert b["my_key.does stuff.to get to"] == "where I want"
        b["my_key.does stuff.to get to"] = "test"
        assert b["my_key.does stuff.to get to"] == "test"
        del b["my_key.does stuff"]
        assert b["my_key"] == {}
        b[4] = 2
        assert b[4] == 2
        del b[4]
        assert b["key.with.list[0][0][0].test"] == "value"
        b["key.with.list[0][0][0].test"] = "new_value"
        assert b["key.with.list"][0][0][0]["test"] == "new_value"
        del b["key.with.list[0][0][0].test"]
        assert not b["key.with.list[0][0][0]"]
        del b["key.with.list[0][0]"]
        with pytest.raises(IndexError):
            b["key.with.list[0][0][0]"]
        del b["key.with.list[0]"]
        with pytest.raises(IndexError):
            b["key.with.list[0][0]"]

        d = Box()
        with pytest.raises(BoxError):
            d.keys(dotted=True)
Ejemplo n.º 2
0
 def test_default_and_camel_killer_box(self):
     td = extended_test_dict.copy()
     td["CamelCase"] = "Item"
     killer_default_box = Box(td, camel_killer_box=True, default_box=True)
     assert killer_default_box.camel_case == "Item"
     assert killer_default_box.CamelCase == "Item"
     assert isinstance(killer_default_box.does_not_exist, Box)
     assert isinstance(killer_default_box["does_not_exist"], Box)
Ejemplo n.º 3
0
 def test_default_and_camel_killer_box(self):
     td = extended_test_dict.copy()
     td['CamelCase'] = 'Item'
     killer_default_box = Box(td, camel_killer_box=True, default_box=True)
     assert killer_default_box.camel_case == 'Item'
     assert killer_default_box.CamelCase == 'Item'
     assert isinstance(killer_default_box.does_not_exist, Box)
     assert isinstance(killer_default_box['does_not_exist'], Box)
Ejemplo n.º 4
0
    def test_camel_killer_box(self):
        td = extended_test_dict.copy()
        td["CamelCase"] = "Item"
        td["321CamelCaseFever!"] = "Safe"

        kill_box = Box(td, camel_killer_box=True, conversion_box=False)
        assert kill_box.camel_case == "Item"
        assert kill_box["321CamelCaseFever!"] == "Safe"

        con_kill_box = Box(td, conversion_box=True, camel_killer_box=True)
        assert con_kill_box.camel_case == "Item"
        assert con_kill_box.x321_camel_case_fever == "Safe"
Ejemplo n.º 5
0
    def test_camel_killer_box(self):
        td = extended_test_dict.copy()
        td['CamelCase'] = 'Item'
        td['321CamelCaseFever!'] = 'Safe'

        kill_box = Box(td, camel_killer_box=True, conversion_box=False)
        assert kill_box.camel_case == 'Item'
        assert kill_box['321CamelCaseFever!'] == 'Safe'

        con_kill_box = Box(td, conversion_box=True, camel_killer_box=True)
        assert con_kill_box.camel_case == 'Item'
        assert con_kill_box.x321_camel_case_fever == 'Safe'