2024-04-09 01:36:47 +00:00
|
|
|
import pytest
|
|
|
|
|
2024-09-03 01:13:28 +00:00
|
|
|
from typing import Tuple, Callable
|
2024-04-09 01:36:47 +00:00
|
|
|
import numpy as np
|
|
|
|
import dask.array as da
|
2024-04-30 02:49:38 +00:00
|
|
|
import zarr
|
2024-09-03 01:13:28 +00:00
|
|
|
from pydantic import BaseModel
|
2024-04-09 01:36:47 +00:00
|
|
|
|
2024-09-03 01:13:28 +00:00
|
|
|
from numpydantic import interface, NDArray
|
2024-04-09 01:36:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=[
|
|
|
|
([[1, 2], [3, 4]], interface.NumpyInterface),
|
|
|
|
(np.zeros((3, 4)), interface.NumpyInterface),
|
2024-05-09 05:06:41 +00:00
|
|
|
("hdf5_array", interface.H5Interface),
|
2024-04-09 01:36:47 +00:00
|
|
|
(da.random.random((10, 10)), interface.DaskInterface),
|
2024-04-30 02:49:38 +00:00
|
|
|
(zarr.ones((10, 10)), interface.ZarrInterface),
|
2024-05-09 05:06:41 +00:00
|
|
|
("zarr_nested_array", interface.ZarrInterface),
|
|
|
|
("zarr_array", interface.ZarrInterface),
|
2024-09-03 01:13:28 +00:00
|
|
|
("avi_video", interface.VideoInterface),
|
2024-04-30 02:49:38 +00:00
|
|
|
],
|
|
|
|
ids=[
|
|
|
|
"numpy_list",
|
|
|
|
"numpy",
|
|
|
|
"H5ArrayPath",
|
|
|
|
"dask",
|
|
|
|
"zarr_memory",
|
|
|
|
"zarr_nested",
|
|
|
|
"zarr_array",
|
2024-09-03 01:13:28 +00:00
|
|
|
"video",
|
2024-04-09 01:36:47 +00:00
|
|
|
],
|
|
|
|
)
|
2024-09-03 01:13:28 +00:00
|
|
|
def interface_type(request) -> Tuple[NDArray, interface.Interface]:
|
2024-05-09 04:29:13 +00:00
|
|
|
"""
|
|
|
|
Test cases for each interface's ``check`` method - each input should match the
|
|
|
|
provided interface and that interface only
|
|
|
|
"""
|
2024-05-09 05:06:41 +00:00
|
|
|
if isinstance(request.param[0], str):
|
|
|
|
return (request.getfixturevalue(request.param[0]), request.param[1])
|
|
|
|
else:
|
|
|
|
return request.param
|
2024-09-03 01:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def all_interfaces(interface_type) -> BaseModel:
|
|
|
|
"""
|
|
|
|
An instantiated version of each interface within a basemodel,
|
|
|
|
with the array in an `array` field
|
|
|
|
"""
|
|
|
|
array, interface = interface_type
|
|
|
|
if isinstance(array, Callable):
|
|
|
|
array = array()
|
|
|
|
|
|
|
|
class MyModel(BaseModel):
|
|
|
|
array: NDArray
|
|
|
|
|
|
|
|
instance = MyModel(array=array)
|
|
|
|
return instance
|