Пример #1
0
 def test_patch_different_target(self):
     a = OrderedDict((('a', 1), ('b', 2), ('c', 3), ('d', 4)))
     b = OrderedDict((('b', 2), ('a', 1), ('c', 3), ('d', 4)))
     d = diff(a, b)
     c = OrderedDict((('a', 1), ('b', 2), ('e', 9), ('f', 10)))
     self.assertEqual(
         patch(c, d),
         OrderedDict((('b', 2), ('a', 1), ('e', 9), ('f', 10)))
     )
Пример #2
0
from diffr import unchanged, remove, insert, DiffItem, Diff, patch

d = Diff(
    set,
    [DiffItem(remove, 'a'), DiffItem(unchanged, 'b'), DiffItem(insert, 'c')]
)
print(d)
# the diff of 'hi' and 'hello'
d = Diff(
    str,
    [
        DiffItem(unchanged, 'h', (0, 1, 0, 1)),
        DiffItem(remove, 'i', (1, 2, 1, 1)),
        DiffItem(insert, 'e', (2, 2, 1, 2)),
        DiffItem(insert, 'l', (2, 2, 2, 3)),
        DiffItem(insert, 'l', (2, 2, 3, 4)),
        DiffItem(insert, 'o', (2, 2, 4, 5))
    ]
)
print(d)
# patching 'hi' with this diff should produce 'hello'
print(patch('hi', d))
Пример #3
0
from diffr import diff, patch

a = [1, 2, 3]
b = [2, 1, 3, 4]
d = diff(a, b)
print(d)
should_be_b = patch(a, d)
print(should_be_b)
print(b == should_be_b)
a = {
    'first_name': 'John',
    'last_name': 'Smith',
    'age': 24
}
b = {
    'first_name': 'Jenny',
    'last_name': 'Smith',
    'age': 32
}
d = diff(a, b)
print(d)
should_be_b = patch(a, d)
print(should_be_b)
print(b == should_be_b)