[Git][reproducible-builds/diffoscope][master] Use "xz --list" to supplement output when comparing .xz archives; essential...

Chris Lamb (@lamby) gitlab at salsa.debian.org
Thu May 9 09:01:22 UTC 2024



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
49871a42 by Chris Lamb at 2024-05-09T10:00:47+01:00
Use "xz --list" to supplement output when comparing .xz archives; essential when metadata differs. (Closes: Debian:#1069329)

- - - - -


2 changed files:

- diffoscope/comparators/xz.py
- tests/comparators/test_xz.py


Changes:

=====================================
diffoscope/comparators/xz.py
=====================================
@@ -23,13 +23,21 @@ import logging
 import subprocess
 
 from diffoscope.tools import tool_required
+from diffoscope.difference import Difference
 
 from .utils.file import File
 from .utils.archive import Archive
+from .utils.command import Command
 
 logger = logging.getLogger(__name__)
 
 
+class XZList(Command):
+    @tool_required("xz")
+    def cmdline(self):
+        return ("xz", "--list", "--verbose", self.path)
+
+
 class XzContainer(Archive):
     def open_archive(self):
         return self
@@ -61,3 +69,10 @@ class XzFile(File):
     # Work around file(1) Debian bug #876316
     FALLBACK_FILE_EXTENSION_SUFFIX = {".xz"}
     FALLBACK_FILE_TYPE_HEADER_PREFIX = b"\xfd7zXZ\x00"
+
+    def compare_details(self, other, source=None):
+        return [
+            Difference.from_operation(
+                XZList, self.path, other.path, source="xz --list"
+            )
+        ]


=====================================
tests/comparators/test_xz.py
=====================================
@@ -24,7 +24,7 @@ from diffoscope.comparators.xz import XzFile
 from diffoscope.comparators.binary import FilesystemFile
 from diffoscope.comparators.utils.specialize import specialize
 
-from ..utils.data import load_fixture, get_data
+from ..utils.data import load_fixture, assert_diff
 from ..utils.tools import skip_unless_tools_exist
 from ..utils.nonexisting import assert_non_existing
 
@@ -48,8 +48,10 @@ def differences(xz1, xz2):
 
 @skip_unless_tools_exist("xz")
 def test_content_source(differences):
-    assert differences[0].source1 == "test1"
-    assert differences[0].source2 == "test2"
+    assert differences[0].source1 == "xz --list"
+    assert differences[0].source2 == "xz --list"
+    assert differences[1].source1 == "test1"
+    assert differences[1].source2 == "test2"
 
 
 @skip_unless_tools_exist("xz")
@@ -61,14 +63,14 @@ def test_content_source_without_extension(tmpdir, xz1, xz2):
     xz1 = specialize(FilesystemFile(path1))
     xz2 = specialize(FilesystemFile(path2))
     difference = xz1.compare(xz2).details
-    assert difference[0].source1 == "test1-content"
-    assert difference[0].source2 == "test2-content"
+    assert difference[1].source1 == "test1-content"
+    assert difference[1].source2 == "test2-content"
 
 
 @skip_unless_tools_exist("xz")
 def test_content_diff(differences):
-    expected_diff = get_data("text_ascii_expected_diff")
-    assert differences[0].unified_diff == expected_diff
+    assert_diff(differences[0], "text_xz_list")
+    assert_diff(differences[1], "text_ascii_expected_diff")
 
 
 @skip_unless_tools_exist("xz")



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/49871a42eb8206dc1379ca8871001ebaddf5d083

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/49871a42eb8206dc1379ca8871001ebaddf5d083
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/20240509/fb862824/attachment.htm>


More information about the rb-commits mailing list