Commit dbf5350f authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Add support for detecting ordering-only differences in XML files. (Closes:...

Add support for detecting ordering-only differences in XML files. (Closes: #317, Debian:#1022146)
parent a6a0f90b
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -131,11 +131,14 @@ class XMLFile(File):
                )
            ]

        return [
            Difference.from_text(
        difference = Difference.from_text(
            self.dumps(self), self.dumps(other), self.name, other.name
        )
        ]

        if difference:
            difference.check_for_ordering_differences()

        return [difference]

    def dumps(self, file):
        """
+11 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ from ..utils.data import load_fixture, assert_diff

xml_a = load_fixture("test1.xml")
xml_b = load_fixture("test2.xml")
xml_c = load_fixture("test3.xml")
xml_d = load_fixture("test4.xml")
invalid_xml = load_fixture("test_invalid.xml")


@@ -52,3 +54,12 @@ def differences(xml_a, xml_b):
)
def test_diff(differences):
    assert_diff(differences[0], "test_xml_expected_diff")


@pytest.mark.skipif(
    sys.version_info < (3, 8), reason="requires Python 3.8 or higher"
)
def test_ordering_differences(xml_c, xml_d):
    diff = xml_c.compare(xml_d)
    assert diff.details[0].comments == ["Ordering differences only"]
    assert_diff(diff.details[0], "test_xml_ordering_differences_diff")

tests/data/test3.xml

0 → 100644
+5 −0
Original line number Diff line number Diff line
<?xml version='1.0' encoding='UTF-8' ?>
<foo>
	<bar attr='foo'/>
	<bar attr='bar'/>
</foo>

tests/data/test4.xml

0 → 100644
+5 −0
Original line number Diff line number Diff line
<?xml version='1.0' encoding='UTF-8' ?>
<foo>
	<bar attr='bar'/>
	<bar attr='foo'/>
</foo>
+7 −0
Original line number Diff line number Diff line
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <foo>
-  <bar attr="foo"/>
   <bar attr="bar"/>
+  <bar attr="foo"/>
 </foo>
Loading