numpydantic/tests/test_interface/test_dask.py

48 lines
1.1 KiB
Python
Raw Normal View History

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
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()
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:
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):
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):
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