[Git][reproducible-builds/diffoscope][master] 5 commits: Use assert_diff over get_data and manual assert.
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Wed Oct 26 20:07:33 UTC 2022
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
a6a0f90b by Chris Lamb at 2022-10-26T12:56:31-07:00
Use assert_diff over get_data and manual assert.
- - - - -
dbf5350f by Chris Lamb at 2022-10-26T13:03:43-07:00
Add support for detecting ordering-only differences in XML files. (Closes: reproducible-builds/diffoscope#317, Debian:#1022146)
- - - - -
844e00c7 by Chris Lamb at 2022-10-26T13:03:43-07:00
Use capitalised "Ordering".
- - - - -
7f0407a1 by Chris Lamb at 2022-10-26T13:03:43-07:00
Tidy up test_json file.
- - - - -
1bb51831 by Chris Lamb at 2022-10-26T13:03:43-07:00
Rename order1.diff to json_expected_ordering_diff.
- - - - -
9 changed files:
- diffoscope/comparators/json.py
- diffoscope/comparators/xml.py
- tests/comparators/test_json.py
- tests/comparators/test_xml.py
- tests/data/order1.diff → tests/data/json_expected_ordering_diff
- + tests/data/test3.xml
- + tests/data/test4.xml
- + tests/data/test_xml_ordering_differences_diff
- tests/test_source.py
Changes:
=====================================
diffoscope/comparators/json.py
=====================================
@@ -76,7 +76,7 @@ class JSONFile(File):
self.path,
other.path,
source="Pretty-printed",
- comment="ordering differences only",
+ comment="Ordering differences only",
)
return [difference]
=====================================
diffoscope/comparators/xml.py
=====================================
@@ -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):
"""
=====================================
tests/comparators/test_json.py
=====================================
@@ -1,7 +1,7 @@
#
# diffoscope: in-depth comparison of files, archives, and directories
#
-# Copyright © 2016-2017, 2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2017, 2020, 2022 Chris Lamb <lamby at 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")
=====================================
tests/comparators/test_xml.py
=====================================
@@ -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")
+
+
+ at 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/order1.diff → tests/data/json_expected_ordering_diff
=====================================
=====================================
tests/data/test3.xml
=====================================
@@ -0,0 +1,5 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<foo>
+ <bar attr='foo'/>
+ <bar attr='bar'/>
+</foo>
=====================================
tests/data/test4.xml
=====================================
@@ -0,0 +1,5 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<foo>
+ <bar attr='bar'/>
+ <bar attr='foo'/>
+</foo>
=====================================
tests/data/test_xml_ordering_differences_diff
=====================================
@@ -0,0 +1,7 @@
+@@ -1,5 +1,5 @@
+ <?xml version="1.0" encoding="utf-8"?>
+ <foo>
+- <bar attr="foo"/>
+ <bar attr="bar"/>
++ <bar attr="foo"/>
+ </foo>
=====================================
tests/test_source.py
=====================================
@@ -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",
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/727b3c9ea54b89465d2308997aa8b4bd25bff07f...1bb51831438847ca06914a662e5f602430692a69
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/727b3c9ea54b89465d2308997aa8b4bd25bff07f...1bb51831438847ca06914a662e5f602430692a69
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20221026/989a86be/attachment.htm>
More information about the rb-commits
mailing list