[Git][reproducible-builds/diffoscope][master] Avoid spurious differences in h5dump output caused by exposure of absolute...

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue Jul 8 21:28:20 UTC 2025



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
2d752e7e by Chris Lamb at 2025-07-08T14:25:44-07:00
Avoid spurious differences in h5dump output caused by exposure of absolute internal extraction paths. (Closes: #1108690)

- - - - -


3 changed files:

- diffoscope/comparators/hdf.py
- tests/comparators/test_hdf.py
- tests/data/hdf5_expected_diff


Changes:

=====================================
diffoscope/comparators/hdf.py
=====================================
@@ -30,6 +30,12 @@ class H5dump(Command):
     def cmdline(self):
         return ["h5dump", self.path]
 
+    def filter(self, line):
+        # Strip absolute `HDF5 "/path/to/filename.db"`
+        return re.sub(
+            r"^(HDF5) \"[^\"]+\"", "\\1", line.decode("utf-8")
+        ).encode("utf-8")
+
 
 class Hdf5File(File):
     DESCRIPTION = "Hierarchical Data Format database"


=====================================
tests/comparators/test_hdf.py
=====================================
@@ -16,22 +16,19 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import re
 import pytest
 
 from diffoscope.comparators.hdf import Hdf5File
 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, skip_unless_module_exists
 from ..utils.nonexisting import assert_non_existing
 
 hdf5_1 = load_fixture("test1.hdf5")
 hdf5_2 = load_fixture("test2.hdf5")
 
-re_normalise = re.compile(r'(HDF5 ")[^\"]+/([^\"]+")')
-
 
 def hdf5_fixture(prefix):
     @pytest.fixture
@@ -41,8 +38,8 @@ def hdf5_fixture(prefix):
         # Listed in debian/tests/control.in
         import h5py
 
-        with h5py.File(filename, "w"):
-            pass
+        with h5py.File(filename, "w") as f:
+            f.create_dataset(prefix, (100,), dtype="i")
 
         return specialize(FilesystemFile(filename))
 
@@ -72,12 +69,7 @@ def differences(hdf5_1, hdf5_2):
 @skip_unless_tools_exist("h5dump")
 @skip_unless_module_exists("h5py")
 def test_diff(differences):
-    expected_diff = get_data("hdf5_expected_diff")
-    # Remove absolute build path
-    normalised = re_normalise.sub(
-        lambda m: m.group(1) + m.group(2), differences[0].unified_diff
-    )
-    assert normalised == expected_diff
+    assert_diff(differences[0], "hdf5_expected_diff")
 
 
 @skip_unless_tools_exist("h5dump")


=====================================
tests/data/hdf5_expected_diff
=====================================
@@ -1,6 +1,12 @@
-@@ -1,4 +1,4 @@
--HDF5 "test1.db" {
-+HDF5 "test2.db" {
+@@ -1,10 +1,10 @@
+ HDF5 {
  GROUP "/" {
- }
- }
+-   DATASET "test1" {
++   DATASET "test2" {
+       DATATYPE  H5T_STD_I32LE
+       DATASPACE  SIMPLE { ( 100 ) / ( 100 ) }
+       DATA {
+       (0): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       (22): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       (44): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+       (66): 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,



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

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/commit/2d752e7ead892714bed836ee3d95e9500be06ee6
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/20250708/dd41f0bf/attachment.htm>


More information about the rb-commits mailing list