Skip to content

Commit 776902d

Browse files
committed
Added complete integration write-read test
1 parent ed48340 commit 776902d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

cfapyx/tests/test_write.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22

33
from cfapyx import CFANetCDF
4+
import xarray as xr
45

56
TESTDIR = 'cfapyx/tests/test_space'
67

@@ -27,5 +28,41 @@ def test_cfa_write(self, testdir=TESTDIR):
2728

2829
print('Integration tests: Write - complete')
2930

31+
FILE = f'{testdir}/testrain.nca'
32+
33+
# Local testing: Add CFAPyX before tests
34+
try:
35+
ds = xr.open_dataset(FILE, engine='CFA')
36+
except Exception as err:
37+
assert isinstance(err, ImportError)
38+
print('Integration tests: Read(pure) - skipped')
39+
return
40+
41+
## Test global dataset
42+
assert not hasattr(ds,'address')
43+
assert not hasattr(ds,'shape')
44+
assert not hasattr(ds,'location')
45+
46+
assert 'p' in ds
47+
assert ds['p'].shape == (20, 180, 360)
48+
49+
# Using selection with lat/lon values NOT index values
50+
p_sel = ds['p'].isel(time=slice(0,3),latitude=slice(140,145), longitude=slice(90,100))
51+
52+
assert p_sel.shape == (3, 5, 10)
53+
assert not hasattr(p_sel, 'aggregated_data')
54+
assert not hasattr(p_sel, 'aggregated_dimensions')
55+
p_mean = p_sel.mean(dim='time')
56+
57+
assert p_mean.shape == (5, 10)
58+
assert abs(p_mean[0][0].to_numpy() - 0.635366) < 0.01, "Pure Data Invalid"
59+
60+
p_value = p_sel.mean()
61+
62+
assert p_value.shape == ()
63+
assert abs(p_value.to_numpy() - 0.511954) < 0.01, "Pure Data Invalid"
64+
65+
print('Integration tests: Write-Read(pure) - complete')
66+
3067
if __name__ == '__main__':
3168
TestCFAWrite().test_cfa_write()

0 commit comments

Comments
 (0)