Exemplo n.º 1
0
    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)
        )
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
 def testOverwrite(self):
     old_structure = {'a': {'b': {}}}
     new_structure = {'a': {'c': {}}}
     self.assertEquals(
         {'+':{}, '*': new_structure, '-': []},
         diff.diff_structures(old_structure, new_structure)
     )
Exemplo n.º 4
0
 def testModifications(self):
     old_structure = {'a': 'b'}
     new_structure = {'a': 'z'}
     self.assertEquals(
         {'+':{}, '*':{'a':'z'}, '-':[]},
         diff.diff_structures(old_structure, new_structure)
     )
Exemplo n.º 5
0
    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([], {})
        )
Exemplo n.º 6
0
 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))