diff --git a/test/base_test.py b/test/base_test.py index f8a30a5..a027413 100644 --- a/test/base_test.py +++ b/test/base_test.py @@ -52,10 +52,9 @@ def test_attr_on_root(self, server): retrieved_attributes = decode_response(response) assert retrieved_attributes == nx_attributes - @pytest.mark.parametrize("format_arg", ("json", "npy")) - @pytest.mark.parametrize("flatten", (False, True)) - def test_data_on_array(self, server, format_arg, flatten): - """Test /data/ endpoint on array dataset in a group""" + @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""" # Test condition tested_h5entity_path = "/entry/image" data = np.random.random((128, 128)) @@ -65,40 +64,40 @@ def test_data_on_array(self, server, format_arg, flatten): h5file[tested_h5entity_path] = data response = server.get( - f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': format_arg, 'flatten': flatten})}" + f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': format_arg})}" + ) + retrieved_data = decode_array_response( + response, format_arg, data.dtype.str, data.shape ) - retrieved_data = np.array(decode_response(response, format_arg)) - assert np.array_equal(retrieved_data, data.flatten() if flatten else data) + assert np.array_equal(retrieved_data, data) @pytest.mark.parametrize("format_arg", ("npy", "bin")) - @pytest.mark.parametrize("dtype_arg", ("origin", "safe")) - def test_data_on_array_with_dtype(self, server, format_arg, dtype_arg): - """Test /data/ endpoint on array dataset with dtype""" + def test_data_on_array_with_dtype_safe( + self, + server, + format_arg, + ): + """Test /data/ endpoint on array dataset with dtype=safe""" # Test condition tested_h5entity_path = "/entry/image" data = np.random.random((128, 128)).astype(">f2") # No Float16Array in JS => converted to float32 - ref_dtype = "f2" filename = "test.h5" with h5py.File(server.served_directory / filename, mode="w") as h5file: h5file[tested_h5entity_path] = data response = server.get( - f"/data/?{urlencode({'file': filename, 'path': tested_h5entity_path, 'format': format_arg, 'dtype': dtype_arg})}" - ) - - 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'})}" ) + retrieved_data = decode_array_response(response, format_arg, " np.ndarray: """Decode data array response content according to given information""" content_type = response.find_header_value("content-type")