def test_set_in(): nested = Object({"key": [{"abc": 123}, {"def": 456}], "other": 0}) insert = Object({"xyz": 789}) assert nested.set_in(["key", 0], insert) == {"key": [{"xyz": 789}, {"def": 456}], "other": 0} assert nested.set_in(["key"], insert) == {"key": {"xyz": 789}, "other": 0} assert nested.set_in([], insert) == {"xyz": 789}
def test_set_in(): nested = Object({'key': [{'abc': 123}, {'def': 456}], 'other': 0}) insert = Object({'xyz': 789}) assert (nested.set_in(['key', 0], insert) == { 'key': [{ 'xyz': 789 }, { 'def': 456 }], 'other': 0 }) assert (nested.set_in(['key'], insert) == { 'key': { 'xyz': 789 }, 'other': 0 }) assert nested.set_in([], insert) == {'xyz': 789}
def test_object_data_and_links_properties(): obj = Object({'a': 1, 'b': 2, 'c': Link(), 'd': Link()}) assert sorted(list(obj.data.keys())) == ['a', 'b'] assert sorted(list(obj.links.keys())) == ['c', 'd']
def test_object_keys_must_be_strings(): with pytest.raises(TypeError): Object(content={0: 123})
def obj(): return Object({'key': 'value', 'nested': {'abc': 123}})
def test_delete_in(): nested = Object({'key': [{'abc': 123}, {'def': 456}], 'other': 0}) assert nested.delete_in(['key', 0]) == {'key': [{'def': 456}], 'other': 0} assert nested.delete_in(['key']) == {'other': 0} assert nested.delete_in([]) is None
def test_delete_in(): nested = Object({"key": [{"abc": 123}, {"def": 456}], "other": 0}) assert nested.delete_in(["key", 0]) == {"key": [{"def": 456}], "other": 0} assert nested.delete_in(["key"]) == {"other": 0} assert nested.delete_in([]) is None