def check_diff(self, data1, data2, added, deleted): diff1 = datadiff.diff(data1, data2) self.assertEqual(added, diff1.added) self.assertEqual(deleted, diff1.deleted) diff2 = datadiff.diff(data2, data1) self.assertEqual(deleted, diff2.added) self.assertEqual(added, diff2.deleted) diff3 = datadiff.diff(data2, data2) self.assertFalse(diff3.added) self.assertFalse(diff3.deleted)
def test_diff_iterable(self): data1 = ({x: x} for x in six.moves.range(3)) data2 = ({x: x} for x in six.moves.range(1, 4)) diff1 = datadiff.diff(data1, data2) self.assertEqual([{3: 3}], diff1.added) self.assertEqual([{0: 0}], diff1.deleted) data1 = six.moves.filter(None, six.moves.range(3)) data2 = six.moves.filter(None, six.moves.range(4)) diff2 = datadiff.diff(data1, data2) self.assertEqual([3], diff2.added) self.assertEqual([], diff2.deleted)
def deleted(expression, context, engine): new_data = get_limited_if_need(get_new(expression, context), engine) old_data = get_limited_if_need(get_old(expression, context), engine) if old_data is not _UNDEFINED: return datadiff.diff(old_data, new_data).deleted
def test_diff_for_different_types(self): d = datadiff.diff({1, 2}, [1, 2]) self.assertEqual([1, 2], d.added) self.assertEqual({1, 2}, d.deleted)
def test_diff_simple(self): diff = datadiff.diff("abc\nbcd", "bcd\ncda") self.assertEqual(["cda"], diff.added) self.assertEqual(["abc"], diff.deleted)
def test_diff_range(self): diff1 = datadiff.diff(six.moves.range(3), six.moves.range(1, 4)) self.assertEqual([3], diff1.added) self.assertEqual([0], diff1.deleted)