def testDiffEmpty(self): full_structure = { 'mario': 1, 'luigi': 2 } self.assertEquals( {'+':{}, '*':{}, '-':full_structure.keys()}, diff.diff_structures(full_structure, {}) ) self.assertEquals( {'+':full_structure, '*':{}, '-':[]}, diff.diff_structures({}, full_structure) ) full_list = ['zoo', False, None] self.assertEquals( {'+':{}, '*':{}, '-':['0', '1', '2']}, diff.diff_structures(full_list, []) ) self.assertEquals( { '+':dict(zip( map(str, range(len(full_list))), full_list )), '*':{}, '-':[] }, diff.diff_structures([], full_list) )
def testPatch(self): a = {'hello': 'there', 'done': None} b = {'hello': 'hola', 'tank': False, 'gas': 8} patch = diff.diff_structures(a, b) self.assertEquals(b, diff.patch(a, patch)) a = ['hello'] b = ['hola', False, None] patch = diff.diff_structures(a, b) self.assertEquals(b, diff.patch(a, patch))
def testOverwrite(self): old_structure = {'a': {'b': {}}} new_structure = {'a': {'c': {}}} self.assertEquals( {'+':{}, '*': new_structure, '-': []}, diff.diff_structures(old_structure, new_structure) )
def testModifications(self): old_structure = {'a': 'b'} new_structure = {'a': 'z'} self.assertEquals( {'+':{}, '*':{'a':'z'}, '-':[]}, diff.diff_structures(old_structure, new_structure) )
def testDiffNoChange(self): no_change_result = {'+':{}, '*':{}, '-':[]} self.assertEquals( no_change_result, diff.diff_structures({}, {}) ) self.assertEquals( no_change_result, diff.diff_structures([], []) ) # not sure how to handle these, but they don't seem problematic self.assertEquals( no_change_result, diff.diff_structures({}, []) ) self.assertEquals( no_change_result, diff.diff_structures([], {}) )
def testPatchNested(self): a = {'a': {'b': {'c': 7}}} b = {'a': {'b': {'d': 7}}} patch = diff.diff_structures(a, b) self.assertEquals(b, diff.patch(a, patch))