Commits (5)
......@@ -76,7 +76,7 @@ class JSONFile(File):
self.path,
other.path,
source="Pretty-printed",
comment="ordering differences only",
comment="Ordering differences only",
)
return [difference]
......
......@@ -131,11 +131,14 @@ class XMLFile(File):
)
]
return [
Difference.from_text(
self.dumps(self), self.dumps(other), self.name, other.name
)
]
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):
"""
......
#
# diffoscope: in-depth comparison of files, archives, and directories
#
# Copyright © 2016-2017, 2020 Chris Lamb <lamby@debian.org>
# Copyright © 2016-2017, 2020, 2022 Chris Lamb <lamby@debian.org>
#
# diffoscope is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -20,7 +20,7 @@ import pytest
from diffoscope.comparators.json import JSONFile
from ..utils.data import load_fixture, get_data
from ..utils.data import load_fixture, assert_diff
from ..utils.nonexisting import assert_non_existing
......@@ -49,9 +49,7 @@ def differences(json1, json2):
def test_diff(differences):
expected_diff = get_data("json_expected_diff")
assert differences[0].unified_diff == expected_diff
assert_diff(differences[0], "json_expected_diff")
def test_compare_non_existing(monkeypatch, json1):
......@@ -60,5 +58,5 @@ def test_compare_non_existing(monkeypatch, json1):
def test_ordering_differences(json3a, json3b):
diff = json3a.compare(json3b)
assert diff.details[0]._comments == ["ordering differences only"]
assert diff.details[0].unified_diff == get_data("order1.diff")
assert diff.details[0].comments == ["Ordering differences only"]
assert_diff(diff.details[0], "json_expected_ordering_diff")
......@@ -22,11 +22,13 @@ import pytest
from diffoscope.comparators.xml import XMLFile
from ..utils.data import load_fixture, get_data
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")
......@@ -51,5 +53,13 @@ def differences(xml_a, xml_b):
sys.version_info < (3, 8), reason="requires Python 3.8 or higher"
)
def test_diff(differences):
expected_diff = get_data("test_xml_expected_diff")
assert differences[0].unified_diff == expected_diff
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")
<?xml version='1.0' encoding='UTF-8' ?>
<foo>
<bar attr='foo'/>
<bar attr='bar'/>
</foo>
<?xml version='1.0' encoding='UTF-8' ?>
<foo>
<bar attr='bar'/>
<bar attr='foo'/>
</foo>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<foo>
- <bar attr="foo"/>
<bar attr="bar"/>
+ <bar attr="foo"/>
</foo>
......@@ -214,10 +214,12 @@ ALLOWED_TEST_FILES = {
"test3.changes",
"test3.gif",
"test3.pdf",
"test3.xml",
"test3.zip",
"test4.changes",
"test4.gif",
"test4.pdf",
"test4.xml",
"test5.changes",
"test_comment1.zip",
"test_comment2.zip",
......