2024-10-04 07:46:49 +00:00
|
|
|
import inspect
|
2024-09-21 01:28:38 +00:00
|
|
|
from typing import Callable, Tuple, Type
|
2024-10-04 02:57:54 +00:00
|
|
|
|
|
|
|
import pytest
|
2024-09-03 01:13:28 +00:00
|
|
|
from pydantic import BaseModel
|
2024-04-09 01:36:47 +00:00
|
|
|
|
2024-10-04 02:57:54 +00:00
|
|
|
from numpydantic import NDArray, interface
|
2024-10-04 07:46:49 +00:00
|
|
|
from numpydantic.testing.helpers import InterfaceCase
|
|
|
|
from numpydantic.testing.interfaces import (
|
|
|
|
DaskCase,
|
|
|
|
HDF5Case,
|
|
|
|
NumpyCase,
|
|
|
|
VideoCase,
|
|
|
|
ZarrCase,
|
|
|
|
ZarrDirCase,
|
|
|
|
ZarrNestedCase,
|
|
|
|
)
|
2024-04-09 01:36:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=[
|
2024-09-23 20:28:38 +00:00
|
|
|
pytest.param(
|
|
|
|
([[1, 2], [3, 4]], interface.NumpyInterface),
|
|
|
|
marks=pytest.mark.numpy,
|
|
|
|
id="numpy-list",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(NumpyCase, interface.NumpyInterface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.numpy,
|
|
|
|
id="numpy",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(HDF5Case, interface.H5Interface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.hdf5,
|
|
|
|
id="h5-array-path",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(DaskCase, interface.DaskInterface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.dask,
|
|
|
|
id="dask",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(ZarrCase, interface.ZarrInterface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.zarr,
|
|
|
|
id="zarr-memory",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(ZarrNestedCase, interface.ZarrInterface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.zarr,
|
|
|
|
id="zarr-nested",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(ZarrDirCase, interface.ZarrInterface),
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.zarr,
|
2024-10-04 07:46:49 +00:00
|
|
|
id="zarr-dir",
|
2024-09-23 20:28:38 +00:00
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-04 07:46:49 +00:00
|
|
|
(VideoCase, interface.VideoInterface), marks=pytest.mark.video, id="video"
|
2024-09-23 20:28:38 +00:00
|
|
|
),
|
2024-04-09 01:36:47 +00:00
|
|
|
],
|
|
|
|
)
|
2024-10-04 07:46:49 +00:00
|
|
|
def interface_type(
|
|
|
|
request, tmp_output_dir_func
|
|
|
|
) -> Tuple[NDArray, Type[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-10-04 07:46:49 +00:00
|
|
|
|
|
|
|
if inspect.isclass(request.param[0]) and issubclass(
|
|
|
|
request.param[0], InterfaceCase
|
|
|
|
):
|
|
|
|
array = request.param[0].make_array(path=tmp_output_dir_func)
|
|
|
|
if array is None:
|
|
|
|
pytest.skip()
|
|
|
|
return array, request.param[1]
|
2024-05-09 05:06:41 +00:00
|
|
|
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
|