Commit 2d752e7e authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Avoid spurious differences in h5dump output caused by exposure of absolute...

Avoid spurious differences in h5dump output caused by exposure of absolute internal extraction paths. (Closes: #1108690)
parent 025166b4
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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"
+4 −12
Original line number Diff line number Diff line
@@ -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")
+11 −5
Original line number Diff line number Diff line
@@ -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,