Files
manipulator/test/update_test.py
hellerve e8c62738a1 initial
2017-01-17 14:49:18 +01:00

80 lines
1.9 KiB
Python

from manipulator import update
def test_update_id():
x = [1]
after = [2]
assert update(x, "#0", lambda x: x+1) == [2]
assert x == after
def test_update_id_copy():
x = [1]
assert update(x, "#0", lambda x: x+1, in_place=False) == [2]
assert x == [1]
def test_update_class():
x = [{"k": 1}, {"k": 2}]
after = [{"k": 2}, {"k": 3}]
assert update(x, ".k", lambda x: x+1) == after
assert x == after
def test_update_class_copy():
x = [{"k": 1}, {"k": 2}]
after = [{"k": 2}, {"k": 3}]
assert update(x, ".k", lambda x: x+1, in_place=False) == after
assert x == [{"k": 1}, {"k": 2}]
def test_update_nested_id():
x = [{"k": 1}]
after = [{"k": 2}]
assert update(x, "#0 #k", lambda x: x+1) == after
assert x == after
def test_update_nested_id_copy():
x = [{"k": 1}]
after = [{"k": 2}]
assert update(x, "#0 #k", lambda x: x+1, in_place=False) == after
assert x == [{"k": 1}]
def test_update_nested_class():
x = [{"k": {"k2": 1}}, {"k": {"k2": 2}}]
after = [{"k": {"k2": 2}}, {"k": {"k2": 3}}]
assert update(x, ".k .k2", lambda x: x+1) == after
assert x == after
def test_update_nested_class_copy():
x = [{"k": {"k2": 1}}, {"k": {"k2": 2}}]
after = [{"k": {"k2": 2}}, {"k": {"k2": 3}}]
assert update(x, ".k .k2", lambda x: x+1, in_place=False) == after
assert x == [{"k": {"k2": 1}}, {"k": {"k2": 2}}]
def test_complex_update():
x = [{"k": "v"}, {"k": {"a": [{"k": 10}, {"k": 11}]}}]
after = [{"k": "v"}, {"k": {"a": [{"k": 11}, {"k": 12}]}}]
assert update(x, ".k #1 #a .k", lambda x: x+1) == after
assert x == after
def test_complex_update_copy():
x = [{"k": "v"}, {"k": {"a": [{"k": 10}, {"k": 11}]}}]
after = [{"k": "v"}, {"k": {"a": [{"k": 11}, {"k": 12}]}}]
assert update(x, ".k #1 #a .k", lambda x: x+1, in_place=False) == after
assert x == [{"k": "v"}, {"k": {"a": [{"k": 10}, {"k": 11}]}}]