Skip to content

Commit

Permalink
The paths endpoint now also includes links (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
loichuder authored Feb 13, 2024
1 parent 07f27ec commit fb86800
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions h5grove/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,16 @@ def get_list_of_paths(

names = []

def get_path(name: str):
full_path = hdf_path_join(base_path, name)
def get_path(name: bytes):
full_path = hdf_path_join(base_path, name.decode())
content = create_content(f, full_path, resolve_links)
names.append(content.path)

try:
base_content = create_content(f, base_path, resolve_links)
assert isinstance(base_content, GroupContent)
names.append(base_content.path)
base_content._h5py_entity.visit(get_path)
base_content._h5py_entity.id.links.visit(get_path)
yield names
except NotFoundError as e:
raise create_error(404, str(e))
Expand Down
10 changes: 9 additions & 1 deletion test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,11 @@ def test_paths(self, server):

with h5py.File(server.served_directory / filename, "w") as h5file:
h5file["tree/branch/fruit"] = "apple"
h5file["tree/branch/fruit_2"] = h5py.SoftLink("fruit")
h5file["tree/other_branch"] = 5
h5file["tree_2"] = "birch"
h5file["tree_2/branch"] = h5py.SoftLink("/tree/branch")
h5file["tree_2/trunk"] = "birch"
h5file["tree_3"] = h5py.ExternalLink("test2.h5", "/another_tree")

response = server.get(f"/paths/?file={filename}")
retrieved_paths = decode_response(response)
Expand All @@ -423,8 +426,12 @@ def test_paths(self, server):
"/tree",
"/tree/branch",
"/tree/branch/fruit",
"/tree/branch/fruit_2",
"/tree/other_branch",
"/tree_2",
"/tree_2/branch",
"/tree_2/trunk",
"/tree_3",
]

response = server.get(f"/paths/?file={filename}&path=/tree/branch")
Expand All @@ -433,6 +440,7 @@ def test_paths(self, server):
assert retrieved_paths == [
"/tree/branch",
"/tree/branch/fruit",
"/tree/branch/fruit_2",
]

def test_404_on_non_existing_path(self, server):
Expand Down

0 comments on commit fb86800

Please sign in to comment.