|
11 | 11 | # isort: split
|
12 | 12 |
|
13 | 13 | import hypothesis.extra.numpy as npst
|
14 |
| -import hypothesis.strategies as st |
| 14 | +import numpy as np |
15 | 15 | from hypothesis import given
|
16 | 16 |
|
17 | 17 | import xarray as xr
|
18 |
| - |
19 |
| -an_array = npst.arrays( |
20 |
| - dtype=st.one_of( |
21 |
| - npst.unsigned_integer_dtypes(), npst.integer_dtypes(), npst.floating_dtypes() |
22 |
| - ), |
23 |
| - shape=npst.array_shapes(max_side=3), # max_side specified for performance |
24 |
| -) |
| 18 | +from xarray.testing.strategies import variables |
25 | 19 |
|
26 | 20 |
|
27 | 21 | @pytest.mark.slow
|
28 |
| -@given(st.data(), an_array) |
29 |
| -def test_CFMask_coder_roundtrip(data, arr) -> None: |
30 |
| - names = data.draw( |
31 |
| - st.lists(st.text(), min_size=arr.ndim, max_size=arr.ndim, unique=True).map( |
32 |
| - tuple |
33 |
| - ) |
34 |
| - ) |
35 |
| - original = xr.Variable(names, arr) |
| 22 | +@given(original=variables()) |
| 23 | +def test_CFMask_coder_roundtrip(original) -> None: |
36 | 24 | coder = xr.coding.variables.CFMaskCoder()
|
37 | 25 | roundtripped = coder.decode(coder.encode(original))
|
38 | 26 | xr.testing.assert_identical(original, roundtripped)
|
39 | 27 |
|
40 | 28 |
|
| 29 | +@pytest.mark.xfail |
| 30 | +@pytest.mark.slow |
| 31 | +@given(var=variables(dtype=npst.floating_dtypes())) |
| 32 | +def test_CFMask_coder_decode(var) -> None: |
| 33 | + var[0] = -99 |
| 34 | + var.attrs["_FillValue"] = -99 |
| 35 | + coder = xr.coding.variables.CFMaskCoder() |
| 36 | + decoded = coder.decode(var) |
| 37 | + assert np.isnan(decoded[0]) |
| 38 | + |
| 39 | + |
41 | 40 | @pytest.mark.slow
|
42 |
| -@given(st.data(), an_array) |
43 |
| -def test_CFScaleOffset_coder_roundtrip(data, arr) -> None: |
44 |
| - names = data.draw( |
45 |
| - st.lists(st.text(), min_size=arr.ndim, max_size=arr.ndim, unique=True).map( |
46 |
| - tuple |
47 |
| - ) |
48 |
| - ) |
49 |
| - original = xr.Variable(names, arr) |
| 41 | +@given(original=variables()) |
| 42 | +def test_CFScaleOffset_coder_roundtrip(original) -> None: |
50 | 43 | coder = xr.coding.variables.CFScaleOffsetCoder()
|
51 | 44 | roundtripped = coder.decode(coder.encode(original))
|
52 | 45 | xr.testing.assert_identical(original, roundtripped)
|
0 commit comments