Skip to content

Commit

Permalink
Test track_order not inherited by subgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjala committed Apr 30, 2024
1 parent 79f2d24 commit 890c414
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
4 changes: 2 additions & 2 deletions h5pyd/_hl/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __init__(
params["include_attrs"] = "T"
if bucket:
params["bucket"] = bucket

params["CreateOrder"] = "1" if track_order else "0"

# need some special logic for the first request in local mode
Expand Down Expand Up @@ -403,7 +403,7 @@ def __init__(

Group.__init__(self, self._id, track_order=track_order)

def _getVerboseInfo(self):
def _getVerboseInfo(self):
now = time.time()
if (
self._verboseUpdated is None or now - self._verboseUpdated > VERBOSE_REFRESH_TIME
Expand Down
24 changes: 21 additions & 3 deletions test/hl/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ def fill_attrs(self, track_order):

# https://forum.hdfgroup.org/t/bug-h5arename-fails-unexpectedly/4881
def test_track_order(self):
filename = self.getFileName("track_order_attribute")
filename = self.getFileName("test_test_track_order_attribute")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w')
attrs = self.fill_attrs(track_order=True) # creation order
self.assertEqual(list(attrs),
[str(i) for i in range(100)])

def test_no_track_order(self):
filename = self.getFileName("no_track_order_attribute")
filename = self.getFileName("test_test_no_track_order_attribute")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w')
attrs = self.fill_attrs(track_order=False) # name alphanumeric
self.assertEqual(list(attrs),
Expand All @@ -149,7 +151,8 @@ def fill_attrs2(self, track_order):
return group

def test_track_order_overwrite_delete(self):
filename = self.getFileName("track_order_overwrite_delete")
filename = self.getFileName("test_test_track_order_overwrite_delete")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w')
# issue h5py#1385
group = self.fill_attrs2(track_order=True) # creation order
Expand All @@ -162,6 +165,21 @@ def test_track_order_overwrite_delete(self):
del group.attrs['10']
self.assertNotIn('10', group.attrs)

def test_track_order_not_inherited(self):
"""
Test that if a File has track order enabled and a sub group does not,
that alphanumeric order is used within the sub group
"""
filename = self.getFileName("test_test_track_order_not_inherited")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w', track_order=True)
group = self.f.create_group('test')

for i in range(12):
group.attrs[str(i)] = i

self.assertEqual(list(group.attrs), sorted([str(i) for i in range(12)]))


if __name__ == '__main__':
loglevel = logging.ERROR
Expand Down
8 changes: 4 additions & 4 deletions test/hl/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def test_serverinfo(self):
self.assertTrue(node_count >= 1)
self.assertTrue("isadmin" in info)

"""
def test_create(self):
filename = self.getFileName("new_file")
print("filename:", filename)
Expand Down Expand Up @@ -205,7 +204,6 @@ def test_create(self):

f.close()
self.assertEqual(f.id.id, 0)
"""

def test_open_notfound(self):
# verify open of non-existent file throws exception
Expand Down Expand Up @@ -359,14 +357,16 @@ def populate(self, f):
f[str(i)] = [i]

def test_track_order(self):
filename = self.getFileName("track_order_file")
filename = self.getFileName("test_track_order_file")
print(f"filename: {filename}")
f = h5py.File(filename, 'w', track_order=True) # creation order
self.populate(f)
self.assertEqual(list(f),
[str(i) for i in range(100)])

def test_no_track_order(self):
filename = self.getFileName("no_track_order_file")
filename = self.getFileName("test_no_track_order_file")
print(f"filename: {filename}")
f = h5py.File(filename, 'w', track_order=False) # name alphanumeric
self.populate(f)
self.assertEqual(list(f),
Expand Down
8 changes: 5 additions & 3 deletions test/hl/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def get_count(grp):
# for some reason this test is failing in Travis
return
filename = self.getFileName("test_link_removal")
print(filename)
print(f"filename: {filename}")

f = h5py.File(filename, 'w')
g1 = f.create_group("g1")
Expand Down Expand Up @@ -312,7 +312,8 @@ def populate(self, g):
g[str(i)] = [i]

def test_track_order(self):
filename = self.getFileName("track_order_group")
filename = self.getFileName("test_track_order_group")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w')
g = self.f.create_group('order', track_order=True) # creation order
self.populate(g)
Expand All @@ -322,7 +323,8 @@ def test_track_order(self):
self.assertEqual(list(reversed(g)), list(reversed(ref)))

def test_no_track_order(self):
filename = self.getFileName("no_track_order_group")
filename = self.getFileName("test_no_track_order_group")
print(f"filename: {filename}")
self.f = h5py.File(filename, 'w')
g = self.f.create_group('order', track_order=False) # name alphanumeric
self.populate(g)
Expand Down

0 comments on commit 890c414

Please sign in to comment.