Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dist/python/jsondiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,12 @@ def transform_object_diff(a, b, s, policy=None):
del ac[k]
a_patches = DMP.patch_make(sk, DMP.diff_fromDelta(sk, op['v']))
b_patches = DMP.patch_make(sk, DMP.diff_fromDelta(sk, b[k]['v']))
b_text = DMP.patch_apply(b_patches, sk)[0]
ab_text = DMP.patch_apply(a_patches, b_text)[0]
b_text, b_applied = DMP.patch_apply(b_patches, sk)
ab_text, a_applied = DMP.patch_apply(a_patches, b_text)

if False in a_applied or False in b_applied:
ab_text, a_applied = DMP.patch_apply(a_patches, sk)

diffs = DMP.diff_main(b_text, ab_text)
if len(diffs) > 2:
DMP.diff_cleanupEfficiency(diffs)
Expand Down
18 changes: 18 additions & 0 deletions dist/python/jsondiff/tests/test_differ.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ def test_object_diffs(self):
b = {'blah':{'hi':'there'}, 'num':-10, 'new':{'list':['a', 'b', 'c']}}
self.assertTrue(object_equals(b, apply_object_diff(a, object_diff(a, b))))

def test_bad_transform(self):
o = {'log' : 'Original Captains Log'}
a = {'log' : 'Local Captains Log'}
b = {'log' : 'Remote Captains Log'}

a_diff = diff(o, a)['v']
b_diff = diff(o, b)['v']

a_prime_diff = transform_object_diff(a_diff, b_diff, o)

ob = apply_object_diff(o, b_diff)

self.assertTrue(object_equals(ob, b))

oba = apply_object_diff(ob, a_prime_diff)

self.assertFalse(object_equals(oba, ob))
self.assertTrue(object_equals(oba, a))

if __name__ == '__main__':
unittest.main()