Пример #1
0
def test_create_array():
    doc = {'a': 1}
    p = [{'add': '$.b[5]', 'value': 1}]
    assert patch(doc, p) == {'a': 1, 'b': [None] * 5 + [1]}

    doc = {}
    p = [{'add': '/b/2/1/3/a', 'value': 2}]
    assert patch(doc, p) == {'b': [None, None, [None, [None, None, None, {'a': 2}]]]}
Пример #2
0
def test_create_array():
    doc = {'a': 1}
    p = [{'add': '$.b[5]', 'value': 1}]
    assert patch(doc, p) == {'a': 1, 'b': [None] * 5 + [1]}

    doc = {}
    p = [{'add': '/b/2/1/3/a', 'value': 2}]
    assert patch(doc, p) == {
        'b': [None, None, [None, [None, None, None, {
            'a': 2
        }]]]
    }
Пример #3
0
def test_nested_patch():
    local = {'foo': {'bar': 1, 'baz': 2}}
    other = {'foo': {'bar': 2, 'qux': 3}}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #4
0
def test_nested_patch():
    local = {'foo': {'bar': 1, 'baz': 2}}
    other = {'foo': {'bar': 2, 'qux': 3}}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #5
0
def test_nested_array_patch():
    local = {'foo': [{'bar': 1, 'baz': 2}, {'qux': 3, 'quux': 4}]}
    other = {'foo': [{'bar': 2, 'qux': 3}, {'quux': 4, 'corge': 5}]}
    delta = diff(local, other)
    logging.debug('delta == %s', pprint.pformat(delta))
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #6
0
def test_simple_patch():
    local = {'foo': 1, 'bar': 2}
    other = {'foo': 2, 'baz': 3}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('delta == %s', pprint.pformat(delta))
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #7
0
def test_nested_array_patch():
    local = {'foo': [{'bar': 1, 'baz': 2}, {'qux': 3, 'quux': 4}]}
    other = {'foo': [{'bar': 2, 'qux': 3}, {'quux': 4, 'corge': 5}]}
    delta = diff(local, other)
    logging.debug('delta == %s', pprint.pformat(delta))
    patched = patch(local, delta)
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #8
0
def test_simple_patch():
    local = {'foo': 1, 'bar': 2}
    other = {'foo': 2, 'baz': 3}
    delta = diff(local, other)
    patched = patch(local, delta)
    logging.debug('delta == %s', pprint.pformat(delta))
    logging.debug('patched == %s', pprint.pformat(patched))
    assert patched == other
Пример #9
0
def test_root_array():
    doc = [1, {'a': 2}]
    p = [{'add': '/1/b', 'value': 'test'}]
    assert patch(doc, p) == [1, {'a': 2, 'b': 'test'}]
Пример #10
0
def test_root_array():
    doc = [1, {'a': 2}]
    p = [{'add': '/1/b', 'value': 'test'}]
    assert patch(doc, p) == [1, {'a': 2, 'b': 'test'}]