예제 #1
0
 def test_path_dot_keyname(self):
     a = {'a.b.c': 1, 'a':{'b':{'c':2}}}
     b = {'a.b.c': 2, 'a':{'b':{'c':3}}}
     diff1 = dictdiff.diff(a, b)
     print diff1
     print " ------- a: ", a
     dictdiff.patch(a, diff1)
     print " ------- a: ", a
     self.assertEqual(a['a.b.c'], 2)
     self.assertEqual(a['a']['b']['c'], 3)
예제 #2
0
    def test_patch_2(self):
        a = {'a':{'b':[{'c': [{'d':[{'e': 1, 'f': 2}]}]}]}, 'b': 1}
        b = {'a':{'b':[{'c': [{'d':[{'e': 1}]}]}]}, 'b': 5}
        print " 1 ====================-----"
        print " 1 ---- ", a
        diff1 = dictdiff.diff(a, b)
        print diff1
        dictdiff.patch(a, diff1)
        print " 1 ---- ", a
        print " 1 ====================-----"

        with self.assertRaises(KeyError):
            dictdiff.dot_lookup(a, 'a.b.[0].c.[0].d.[0].f')
        self.assertEqual(a['b'], 5)
예제 #3
0
    def test_path_1(self):
        a = {'a':1}
        b = {'a':2}
        diff1 = dictdiff.diff(a, b)
        dictdiff.patch(a, diff1)
        self.assertEqual(a['a'], 2)

        diff2 = dictdiff.diff(a, b)
        self.assertEqual(len(diff2), 0)

        a = {'a': {'b': 1}}
        b = {'a': {'b': 2}}
        diff1 = dictdiff.diff(a, b)
        dictdiff.patch(a, diff1)
        self.assertEqual(a['a']['b'], 2)

        a = {'a': {'b': 1}}
        b = {'a': {'c': 1}}
        diff1 = dictdiff.diff(a, b)

        dictdiff.patch(a, diff1)
        # print a
        # print "0------------------------"

        self.assertEqual(a['a']['c'], 1)
        with self.assertRaises(KeyError):
            a['a']['b']

        a = {'a': {'b': 1, 'c': {'e': 1}}}
        b = {'a': {'b': 1}}
        diff1 = dictdiff.diff(a, b)
        print "0------------------------"
        print diff1
        dictdiff.patch(a, diff1)
        print a
        print "0------------------------"

        a = {'a': {'b': 1, 'c': {'e': 1}}}
        b = {'a': {'b': 1, 'c': {}}}
        diff1 = dictdiff.diff(a, b)
        print "0------------------------"
        print diff1
        dictdiff.patch(a, diff1)
        print a
        print "0------------------------"