forked from xarray-contrib/xarray-array-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_numpy.py
39 lines (25 loc) · 950 Bytes
/
test_numpy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from types import ModuleType
import hypothesis.strategies as st
import numpy as np
from xarray_array_testing.base import DuckArrayTestMixin
from xarray_array_testing.creation import CreationTests
from xarray_array_testing.indexing import IndexingTests
from xarray_array_testing.reduction import ReductionTests
def create_numpy_array(*, shape, dtype):
return st.builds(np.ones, shape=st.just(shape), dtype=st.just(dtype))
class NumpyTestMixin(DuckArrayTestMixin):
@property
def xp(self) -> ModuleType:
return np
@property
def array_type(self) -> type[np.ndarray]:
return np.ndarray
@staticmethod
def array_strategy_fn(*, shape, dtype):
return create_numpy_array(shape=shape, dtype=dtype)
class TestCreationNumpy(CreationTests, NumpyTestMixin):
pass
class TestReductionNumpy(ReductionTests, NumpyTestMixin):
pass
class TestIndexingNumpy(IndexingTests, NumpyTestMixin):
pass