2024-10-04 02:57:54 +00:00
|
|
|
import pytest
|
2024-04-09 01:36:47 +00:00
|
|
|
|
2024-10-11 06:56:45 +00:00
|
|
|
from numpydantic.testing.cases import (
|
|
|
|
ALL_CASES,
|
|
|
|
ALL_CASES_PASSING,
|
|
|
|
DTYPE_AND_INTERFACE_CASES_PASSING,
|
|
|
|
)
|
|
|
|
from numpydantic.testing.helpers import InterfaceCase, ValidationCase, merge_cases
|
2024-10-04 07:46:49 +00:00
|
|
|
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(
|
2024-10-11 06:56:45 +00:00
|
|
|
NumpyCase,
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.numpy,
|
|
|
|
id="numpy",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-11 06:56:45 +00:00
|
|
|
HDF5Case,
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.hdf5,
|
|
|
|
id="h5-array-path",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-11 06:56:45 +00:00
|
|
|
DaskCase,
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.dask,
|
|
|
|
id="dask",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-11 06:56:45 +00:00
|
|
|
ZarrCase,
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.zarr,
|
|
|
|
id="zarr-memory",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-11 06:56:45 +00:00
|
|
|
ZarrNestedCase,
|
2024-09-23 20:28:38 +00:00
|
|
|
marks=pytest.mark.zarr,
|
|
|
|
id="zarr-nested",
|
|
|
|
),
|
|
|
|
pytest.param(
|
2024-10-11 06:56:45 +00:00
|
|
|
ZarrDirCase,
|
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
|
|
|
),
|
2024-10-11 06:56:45 +00:00
|
|
|
pytest.param(VideoCase, marks=pytest.mark.video, id="video"),
|
2024-04-09 01:36:47 +00:00
|
|
|
],
|
|
|
|
)
|
2024-10-11 06:56:45 +00:00
|
|
|
def interface_cases(request) -> InterfaceCase:
|
|
|
|
"""
|
|
|
|
Fixture for combinatoric tests across all interface cases
|
|
|
|
"""
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
params=(
|
|
|
|
pytest.param(p, id=p.id, marks=getattr(pytest.mark, p.interface.interface.name))
|
|
|
|
for p in ALL_CASES
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def all_cases(interface_cases, request) -> ValidationCase:
|
2024-05-09 04:29:13 +00:00
|
|
|
"""
|
2024-10-11 06:56:45 +00:00
|
|
|
Combinatoric testing for all dtype, shape, and interface cases.
|
|
|
|
|
|
|
|
This is a very expensive fixture! Only use it for core functionality
|
|
|
|
that we want to be sure is *very true* in every circumstance,
|
|
|
|
INCLUDING invalid combinations of annotations and arrays.
|
|
|
|
Typically, that means only use this in `test_interfaces.py`
|
2024-05-09 04:29:13 +00:00
|
|
|
"""
|
2024-10-04 07:46:49 +00:00
|
|
|
|
2024-10-11 06:56:45 +00:00
|
|
|
case = merge_cases(request.param, ValidationCase(interface=interface_cases))
|
|
|
|
if case.skip():
|
|
|
|
pytest.skip()
|
|
|
|
return case
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
params=(
|
|
|
|
pytest.param(p, id=p.id, marks=getattr(pytest.mark, p.interface.interface.name))
|
|
|
|
for p in ALL_CASES_PASSING
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def all_passing_cases(request) -> ValidationCase:
|
|
|
|
"""
|
|
|
|
Combinatoric testing for all dtype, shape, and interface cases,
|
|
|
|
but only the combinations that we expect to pass.
|
|
|
|
|
|
|
|
This is a very expensive fixture! Only use it for core functionality
|
|
|
|
that we want to be sure is *very true* in every circumstance.
|
|
|
|
Typically, that means only use this in `test_interfaces.py`
|
|
|
|
"""
|
|
|
|
return request.param
|
2024-09-03 01:13:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
2024-10-11 06:56:45 +00:00
|
|
|
def all_cases_instance(all_cases, tmp_output_dir_func):
|
2024-09-03 01:13:28 +00:00
|
|
|
"""
|
2024-10-11 06:56:45 +00:00
|
|
|
all_cases but with an instantiated model
|
|
|
|
Args:
|
|
|
|
all_cases:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
|
|
|
array = all_cases.array(path=tmp_output_dir_func)
|
|
|
|
instance = all_cases.model(array=array)
|
|
|
|
return instance
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def all_passing_cases_instance(all_passing_cases, tmp_output_dir_func):
|
2024-09-03 01:13:28 +00:00
|
|
|
"""
|
2024-10-11 06:56:45 +00:00
|
|
|
all_cases but with an instantiated model
|
|
|
|
Args:
|
|
|
|
all_cases:
|
2024-09-03 01:13:28 +00:00
|
|
|
|
2024-10-11 06:56:45 +00:00
|
|
|
Returns:
|
2024-09-03 01:13:28 +00:00
|
|
|
|
2024-10-11 06:56:45 +00:00
|
|
|
"""
|
|
|
|
array = all_passing_cases.array(path=tmp_output_dir_func)
|
|
|
|
instance = all_passing_cases.model(array=array)
|
|
|
|
return instance
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
params=(
|
|
|
|
pytest.param(p, id=p.id, marks=getattr(pytest.mark, p.interface.interface.name))
|
|
|
|
for p in DTYPE_AND_INTERFACE_CASES_PASSING
|
|
|
|
)
|
|
|
|
)
|
|
|
|
def dtype_by_interface(request):
|
|
|
|
"""
|
|
|
|
Tests for all dtypes by all interfaces
|
|
|
|
"""
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture()
|
|
|
|
def dtype_by_interface_instance(dtype_by_interface, tmp_output_dir_func):
|
|
|
|
array = dtype_by_interface.array(path=tmp_output_dir_func)
|
|
|
|
instance = dtype_by_interface.model(array=array)
|
2024-09-03 01:13:28 +00:00
|
|
|
return instance
|