Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests for /data/ endpoint #90

Merged
merged 2 commits into from
Mar 11, 2024
Merged

Add more tests for /data/ endpoint #90

merged 2 commits into from
Mar 11, 2024

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Mar 11, 2024

  • format=tiff and format=csv with numeric array
  • format=bin with opaque dataset

This increases the coverage by a couple of percentage points to 94%. I also reorganise the tests a bit to avoid testing the same things twice.

Comment on lines +55 to +57
@pytest.mark.parametrize("format_arg", ("json", "bin", "npy", "csv", "tiff"))
def test_data_on_array_with_format(self, server, format_arg):
"""Test /data/ endpoint on array dataset"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one now tests all the supported formats without setting the other parameters. This means we no longer need to test flatten: False and dtype: 'origin' in subsequent tests.


retrieved_data = decode_array_response(
response, format_arg, ref_dtype, data.shape
f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': format_arg, 'dtype': 'safe'})}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now focusing on testing dtype: 'safe' in this test.

@@ -108,12 +107,31 @@ def test_data_on_slice(self, server, format_arg, flatten):
h5file[tested_h5entity_path] = data

response = server.get(
f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'selection': '100,0', 'format': format_arg, 'flatten': flatten})}"
f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'selection': '100,0', 'format': format_arg, 'flatten': True})}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now focusing on testing flatten: True in this test.

"format_arg",
("csv", "npy", "tiff"),
)
def test_422_on_format_incompatible_with_non_numeric_data(self, server, format_arg):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To cover the condition that was moved in #89.

raise ValueError(f"Unsupported format: {format}")


def decode_array_response(
response: Response,
format: str,
dtype: str,
shape: Tuple[int],
shape: Tuple[int, ...],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching numpy's internal _Shape type.

@axelboc axelboc merged commit a248a20 into main Mar 11, 2024
1 check passed
@axelboc axelboc deleted the test-bin branch March 11, 2024 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants