2024-05-15 03:18:04 +00:00
|
|
|
import json
|
2024-04-09 01:36:47 +00:00
|
|
|
|
|
|
|
import dask.array as da
|
2024-10-04 02:57:54 +00:00
|
|
|
import pytest
|
2024-04-09 01:36:47 +00:00
|
|
|
|
2024-10-04 02:57:54 +00:00
|
|
|
from numpydantic.interface import DaskInterface
|
2024-10-04 07:46:49 +00:00
|
|
|
from numpydantic.testing.interfaces import DaskCase
|
2024-05-09 05:06:41 +00:00
|
|
|
|
2024-09-23 20:28:38 +00:00
|
|
|
pytestmark = pytest.mark.dask
|
|
|
|
|
2024-05-09 05:06:41 +00:00
|
|
|
|
2024-04-09 01:36:47 +00:00
|
|
|
def test_dask_enabled():
|
|
|
|
"""
|
|
|
|
We need dask to be available to run these tests :)
|
|
|
|
"""
|
|
|
|
assert DaskInterface.enabled()
|
|
|
|
|
|
|
|
|
2024-10-11 06:56:45 +00:00
|
|
|
def test_dask_check(interface_cases, tmp_output_dir_func):
|
|
|
|
array = interface_cases.make_array(path=tmp_output_dir_func)
|
|
|
|
|
|
|
|
if interface_cases.interface is DaskInterface:
|
|
|
|
assert DaskInterface.check(array)
|
2024-04-09 01:36:47 +00:00
|
|
|
else:
|
2024-10-11 06:56:45 +00:00
|
|
|
assert not DaskInterface.check(array)
|
2024-04-09 01:36:47 +00:00
|
|
|
|
|
|
|
|
2024-09-23 20:28:38 +00:00
|
|
|
@pytest.mark.shape
|
2024-05-09 05:06:41 +00:00
|
|
|
def test_dask_shape(shape_cases):
|
2024-10-04 07:46:49 +00:00
|
|
|
shape_cases.interface = DaskCase
|
|
|
|
shape_cases.validate_case()
|
2024-04-09 01:36:47 +00:00
|
|
|
|
|
|
|
|
2024-09-23 20:28:38 +00:00
|
|
|
@pytest.mark.dtype
|
2024-05-09 05:06:41 +00:00
|
|
|
def test_dask_dtype(dtype_cases):
|
2024-10-04 07:46:49 +00:00
|
|
|
dtype_cases.interface = DaskCase
|
|
|
|
dtype_cases.validate_case()
|
2024-05-15 03:18:04 +00:00
|
|
|
|
|
|
|
|
2024-09-23 20:28:38 +00:00
|
|
|
@pytest.mark.serialization
|
2024-05-15 03:18:04 +00:00
|
|
|
def test_dask_to_json(array_model):
|
|
|
|
array_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
|
|
|
|
array = da.array(array_list)
|
|
|
|
model = array_model((3, 3), int)
|
|
|
|
instance = model(array=array)
|
|
|
|
jsonified = json.loads(instance.model_dump_json())
|
|
|
|
assert jsonified["array"] == array_list
|