Skip to content

Commit

Permalink
[test] H5Node of a soft link to an external link
Browse files Browse the repository at this point in the history
  • Loading branch information
woutdenolf committed Dec 11, 2023
1 parent 3d4ae5b commit 95d4d83
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/silx/gui/hdf5/test/test_hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,14 @@ def useH5Model(request, tmpdir_factory):
h5["group/dataset"] = 50
h5["link/soft_link"] = h5py.SoftLink("/group/dataset")
h5["link/soft_link_to_group"] = h5py.SoftLink("/group")
h5["link/soft_link_to_link"] = h5py.SoftLink("/link/soft_link")
h5["link/soft_link_to_soft_link"] = h5py.SoftLink("/link/soft_link")
h5["link/soft_link_to_external_link"] = h5py.SoftLink("/link/external_link")
h5["link/soft_link_to_file"] = h5py.SoftLink("/")
h5["group/soft_link_relative"] = h5py.SoftLink("dataset")
h5["link/external_link"] = h5py.ExternalLink(extH5FileName, "/target/dataset")
h5["link/external_link_to_link"] = h5py.ExternalLink(extH5FileName, "/target/link")
h5["link/external_link_to_soft_link"] = h5py.ExternalLink(
extH5FileName, "/target/link"
)
h5["broken_link/external_broken_file"] = h5py.ExternalLink(
extH5FileName + "_not_exists", "/target/link"
)
Expand Down Expand Up @@ -754,7 +757,7 @@ def testSoftLink(self):
self.assertEqual(h5item.dataLink(qt.Qt.DisplayRole), "Soft")

def testSoftLinkToLink(self):
path = ["base.h5", "link", "soft_link_to_link"]
path = ["base.h5", "link", "soft_link_to_soft_link"]
h5item = self.getH5ItemFromPath(self.model, path)

self.assertEqual(h5item.dataLink(qt.Qt.DisplayRole), "Soft")
Expand All @@ -772,7 +775,7 @@ def testExternalLink(self):
self.assertEqual(h5item.dataLink(qt.Qt.DisplayRole), "External")

def testExternalLinkToLink(self):
path = ["base.h5", "link", "external_link_to_link"]
path = ["base.h5", "link", "external_link_to_soft_link"]
h5item = self.getH5ItemFromPath(self.model, path)

self.assertEqual(h5item.dataLink(qt.Qt.DisplayRole), "External")
Expand Down Expand Up @@ -885,16 +888,30 @@ def testSoftLink(self):
self.assertEqual(h5node.local_basename, "soft_link")
self.assertEqual(h5node.local_name, "/link/soft_link")

def testSoftLinkToLink(self):
path = ["base.h5", "link", "soft_link_to_link"]
def testSoftLinkToSoftLink(self):
path = ["base.h5", "link", "soft_link_to_soft_link"]
h5node = self.getH5NodeFromPath(self.model, path)

self.assertEqual(h5node.physical_filename, h5node.local_filename)
self.assertIn("base.h5", h5node.physical_filename)
self.assertEqual(h5node.physical_basename, "dataset")
self.assertEqual(h5node.physical_name, "/group/dataset")
self.assertEqual(h5node.local_basename, "soft_link_to_link")
self.assertEqual(h5node.local_name, "/link/soft_link_to_link")
self.assertEqual(h5node.local_basename, "soft_link_to_soft_link")
self.assertEqual(h5node.local_name, "/link/soft_link_to_soft_link")

def testSoftLinkToExternalLink(self):
path = ["base.h5", "link", "soft_link_to_external_link"]
h5node = self.getH5NodeFromPath(self.model, path)

with self.assertRaises(KeyError):
# h5py bug: #1706
self.assertNotEqual(h5node.physical_filename, h5node.local_filename)
self.assertIn("base.h5", h5node.local_filename)
self.assertIn("base__external.h5", h5node.physical_filename)
self.assertEqual(h5node.physical_basename, "dataset")
self.assertEqual(h5node.physical_name, "/target/dataset")
self.assertEqual(h5node.local_basename, "soft_link_to_external_link")
self.assertEqual(h5node.local_name, "/link/soft_link_to_external_link")

def testSoftLinkRelative(self):
path = ["base.h5", "group", "soft_link_relative"]
Expand All @@ -919,19 +936,18 @@ def testExternalLink(self):
self.assertEqual(h5node.local_basename, "external_link")
self.assertEqual(h5node.local_name, "/link/external_link")

def testExternalLinkToLink(self):
path = ["base.h5", "link", "external_link_to_link"]
def testExternalLinkToSoftLink(self):
path = ["base.h5", "link", "external_link_to_soft_link"]
h5node = self.getH5NodeFromPath(self.model, path)

self.assertNotEqual(h5node.physical_filename, h5node.local_filename)
self.assertIn("base.h5", h5node.local_filename)
self.assertIn("base__external.h5", h5node.physical_filename)

self.assertNotEqual(h5node.physical_filename, h5node.local_filename)
self.assertEqual(h5node.physical_basename, "dataset")
self.assertEqual(h5node.physical_name, "/target/dataset")
self.assertEqual(h5node.local_basename, "external_link_to_link")
self.assertEqual(h5node.local_name, "/link/external_link_to_link")
self.assertEqual(h5node.local_basename, "external_link_to_soft_link")
self.assertEqual(h5node.local_name, "/link/external_link_to_soft_link")

def testExternalBrokenFile(self):
path = ["base.h5", "broken_link", "external_broken_file"]
Expand Down

0 comments on commit 95d4d83

Please sign in to comment.