Skip to content

Commit

Permalink
Test new type metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Jan 25, 2024
1 parent 0f21787 commit de5ceee
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
pip install -e .[dev]
```

will install `h5grove` in editable mode with all the linting/formating/testing packages. This will also install the [flask](https://flask.palletsprojects.com/en/) and [tornado](https://www.tornadoweb.org/en/stable/) packages as they are needed to build the documentation.
will install `h5grove` in editable mode with all the linting/formating/testing packages. This will also install the [fastapi](https://fastapi.tiangolo.com/), [flask](https://flask.palletsprojects.com/en/) and [tornado](https://www.tornadoweb.org/en/stable/) packages as they are needed to build the documentation and test the project.

## Linting

Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ install_requires =

[options.extras_require]
fastapi =
fastapi
fastapi
pydantic > 2
pydantic-settings
uvicorn
Expand All @@ -35,14 +35,15 @@ flask =
Flask-Compress
Flask-Cors
tornado =
tornado
tornado
dev =
black
bump2version
check-manifest
flake8
h5grove[fastapi]
h5grove[flask]
h5grove[tornado]
invoke
mypy
myst-parser
Expand Down
9 changes: 7 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ def lint(c):


@task
def test(c):
def test(c, verbose=False, keyword="", cov_lines=False):
"""Test without benchmark"""
c.run("pytest --benchmark-skip")
c.run(
"pytest --benchmark-skip"
+ (" -vv" if verbose else "")
+ ((" -k" + keyword) if keyword else "")
+ (" --cov-report term-missing" if cov_lines else "")
)


@task
Expand Down
130 changes: 124 additions & 6 deletions test/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_data_on_array_with_dtype(self, server, format_arg, dtype_arg):
h5file[tested_h5entity_path] = data

response = server.get(
f"/data/?{urlencode({ 'file': filename, 'path': tested_h5entity_path, 'format': format_arg, 'dtype': dtype_arg })}"
f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': format_arg, 'dtype': dtype_arg})}"
)

retrieved_data = decode_array_response(
Expand Down Expand Up @@ -134,11 +134,11 @@ def test_meta_on_chunked_compressed_dataset(self, server):
assert content == {
"attributes": [],
"chunks": [5, 5],
"dtype": "<f8",
"filters": [{"id": 2, "name": "shuffle"}, {"id": 1, "name": "deflate"}],
"kind": "dataset",
"name": "data",
"shape": [10, 10],
"type": {"class": 1, "dtype": "<f8", "size": 8, "order": 0},
}

def test_meta_on_compound_dataset(self, server):
Expand All @@ -161,11 +161,129 @@ def test_meta_on_compound_dataset(self, server):
assert content == {
"attributes": [],
"chunks": None,
"dtype": {"name": "|S10", "age": "<i4", "weight": "<f4"},
"filters": None,
"kind": "dataset",
"name": "dogs",
"shape": [2],
"type": "dataset",
"type": {
"class": 6,
"dtype": {"age": "<i4", "name": "|S10", "weight": "<f4"},
"size": 18,
"members": {
"age": {
"class": 0,
"dtype": "<i4",
"size": 4,
"order": 0,
"sign": 1,
},
"name": {
"class": 3,
"dtype": "|S10",
"size": 10,
"cset": 0,
"vlen": False,
},
"weight": {"class": 1, "dtype": "<f4", "size": 4, "order": 0},
},
},
}

def test_meta_on_compound_dataset_with_advanced_types(self, server):
"""Test /meta/ endpoint on compound dataset with advanced types"""
filename = "test.h5"
tested_h5entity_path = "/foo"

with h5py.File(server.served_directory / filename, mode="w") as h5file:
opaque = np.void(b"\x00\x11\x22")

for_ref = h5file.create_dataset("/bar", data=0)

h5file.create_dataset(
tested_h5entity_path,
data=np.array(
[
(
opaque,
42,
np.array(["bar"], h5py.string_dtype()),
np.array([0], np.uint64),
for_ref.ref,
)
],
dtype=[
("opaque", opaque.dtype),
("enum", h5py.enum_dtype({"H2G2": 42})),
("arr", h5py.string_dtype(), (1,)),
("vlen", h5py.vlen_dtype(np.uint64)),
("ref", h5py.ref_dtype),
],
),
)

response = server.get(f"/meta/?file={filename}&path={tested_h5entity_path}")
content = decode_response(response)

assert content == {
"attributes": [],
"chunks": None,
"filters": None,
"kind": "dataset",
"name": "foo",
"shape": [1],
"type": {
"class": 6,
"dtype": {
"opaque": "|V3",
"enum": "|u1",
"arr": "|V8",
"vlen": "|O",
"ref": "|O",
},
"size": 36,
"members": {
"opaque": {"class": 5, "dtype": "|V3", "size": 3, "tag": ""},
"enum": {
"class": 8,
"dtype": "|u1",
"size": 1,
"members": {"H2G2": 42},
"base": {
"class": 0,
"dtype": "|u1",
"size": 1,
"order": 0,
"sign": 0,
},
},
"arr": {
"class": 10,
"dtype": "|V8",
"size": 8,
"dims": [1],
"base": {
"class": 3,
"dtype": "|O",
"size": 8,
"cset": 1,
"vlen": True,
},
},
"vlen": {
"class": 9,
"dtype": "|O",
"size": 16,
"base": {
"class": 0,
"dtype": "<u8",
"order": 0,
"sign": 0,
"size": 8,
},
},
"ref": {"class": 7, "dtype": "|O", "size": 8},
},
},
}

def test_meta_on_group(self, server):
Expand Down Expand Up @@ -221,11 +339,11 @@ def test_meta_on_valid_ext_link(self, server, resolve_links):
assert content == {
"attributes": [],
"chunks": None,
"dtype": "<f8",
"filters": None,
"kind": "dataset",
"name": "ext_link",
"shape": [10],
"type": {"class": 1, "dtype": "<f8", "order": 0, "size": 8},
}

def test_stats_on_negative_scalar(self, server):
Expand Down Expand Up @@ -358,9 +476,9 @@ def test_meta_on_broken_soft_link(self, server, resolve_links):
response = server.get(url)
content = decode_response(response)
assert content == {
"kind": "soft_link",
"name": "link",
"target_path": "not_an_entity",
"type": "soft_link",
}

def test_403_on_file_without_read_permission(self, server):
Expand Down

0 comments on commit de5ceee

Please sign in to comment.