Esempio n. 1
0
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}
Esempio n. 2
0
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}
Esempio n. 3
0
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']
Esempio n. 4
0
def test_object_keys_must_be_strings():
    with pytest.raises(TypeError):
        Object(content={0: 123})
Esempio n. 5
0
def obj():
    return Object({'key': 'value', 'nested': {'abc': 123}})
Esempio n. 6
0
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
Esempio n. 7
0
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