mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-10 00:34:29 +00:00
27 lines
660 B
Python
27 lines
660 B
Python
import numpy as np
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
from numpydantic.exceptions import DtypeError, ShapeError
|
|
|
|
from tests.conftest import ValidationCase
|
|
|
|
|
|
def numpy_array(case: ValidationCase) -> np.ndarray:
|
|
return np.zeros(shape=case.shape, dtype=case.dtype)
|
|
|
|
|
|
def _test_np_case(case: ValidationCase):
|
|
array = numpy_array(case)
|
|
if case.passes:
|
|
case.model(array=array)
|
|
else:
|
|
with pytest.raises((ValidationError, DtypeError, ShapeError)):
|
|
case.model(array=array)
|
|
|
|
|
|
def test_numpy_shape(shape_cases):
|
|
_test_np_case(shape_cases)
|
|
|
|
|
|
def test_numpy_dtype(dtype_cases):
|
|
_test_np_case(dtype_cases)
|