Skip to content

Commit a210221

Browse files
committed
first draft of the variable creation tests
1 parent ed3c0a9 commit a210221

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

xarray_array_testing/creation.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import hypothesis.strategies as st
2+
import xarray.testing.strategies as xrst
3+
from hypothesis import given
4+
5+
6+
class CreationTests:
7+
array_type: type
8+
9+
@staticmethod
10+
def array_strategy_fn(*, shape, dtype):
11+
raise NotImplementedError
12+
13+
@given(st.data())
14+
def test_create_variable(self, data):
15+
variable = data.draw(xrst.variables(array_strategy_fn=self.array_strategy_fn))
16+
17+
assert isinstance(variable.data, self.array_type)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import hypothesis.strategies as st
2+
import numpy as np
3+
4+
from xarray_array_testing.creation import CreationTests
5+
6+
7+
def create_numpy_array(*, shape, dtype):
8+
return st.builds(np.ones, shape=st.just(shape), dtype=st.just(dtype))
9+
10+
11+
class TestCreationNumpy(CreationTests):
12+
array_type = np.ndarray
13+
array_module = np
14+
15+
@staticmethod
16+
def array_strategy_fn(*, shape, dtype):
17+
return create_numpy_array(shape=shape, dtype=dtype)

0 commit comments

Comments
 (0)