def test_diff_move(self): root_one = etree.fromstring("<root><foo>bar</foo><foo>first</foo></root>") root_two = etree.fromstring("<root><foo>first</foo><foo>bar</foo></root>") script = diff(root_one, root_two) self.assertEqual(1, len(script)) self.assertEqual({ MOVE(path='/root/foo[2]', parent='/root', index=0) }, script)
def test_diff_insert(self): root_one = etree.fromstring("<root></root>") root_two = etree.fromstring("<root><first>A child Node</first></root>") script = diff(root_one, root_two) self.assertEqual(1, len(script)) self.assertEqual({ INSERT(node=b'<first>A child Node</first>', parent='/root', index=0) }, script)
def test_diff_update(self): # This seems to weirdly fail randomly. Check for something out # of order somewhere. root_one = etree.fromstring("<root><first>Some text</first></root>") root_two = etree.fromstring("<root><first>Some text more</first></root>") script = diff(root_one, root_two) self.assertEqual(1, len(script)) self.assertEqual({ UPDATE(path='/root/first', text='Some text more', tail=None, attrib=frozenset()), }, script)
def test_diff_delete(self): root_one = etree.fromstring("<root><foo/></root>") root_two = etree.fromstring("<root></root>") script = diff(root_one, root_two) self.assertEqual(1, len(script)) self.assertEqual({DELETE(path='/root/foo')}, script)
def test_diff_nodiff(self): # These are the same, the edit script should be no different. root_one = etree.fromstring("<root><first><second>Child Node</second></first></root>") root_two = etree.fromstring("<root><first><second>Child Node</second></first></root>") script = diff(root_one, root_two) self.assertEqual(0, len(script))
def xml_compare(r1, r2): diffs = xtdiff.diff(r1, r2) return len(diffs) == 0