21
21
22
22
import glob
23
23
import json
24
+ import unittest
24
25
from abc import ABC , abstractmethod
25
26
from pathlib import Path
26
27
from typing import List
27
- import unittest
28
28
29
29
import fsspec
30
- import numpy as np
31
30
import pytest
32
31
import xarray as xr
33
32
@@ -91,11 +90,14 @@ def tearDownClass(cls):
91
90
def assert_sst_cube_ok (self , cube : xr .Dataset ):
92
91
self .assertEqual ({'time' : 3 , 'lat' : 1350 , 'lon' : 1600 }, cube .sizes )
93
92
self .assertEqual ({'lon' , 'time' , 'lat' }, set (cube .coords ))
94
- self .assertEqual ({'analysis_error' , 'mask' , 'analysed_sst' , 'sea_ice_fraction' },
95
- set (cube .data_vars ))
93
+ self .assertEqual (
94
+ {'analysis_error' , 'mask' , 'analysed_sst' , 'sea_ice_fraction' },
95
+ set (cube .data_vars ))
96
96
sst_ts = cube .isel (lat = 0 , lon = 0 ).compute ()
97
- np .testing .assert_array_equal (sst_ts .analysed_sst .values ,
98
- np .array ([290.02 , 289.94 , 289.89 ]))
97
+ sst_data = sst_ts .analysed_sst .values
98
+ self .assertAlmostEqual (290.02 , sst_data [0 ])
99
+ self .assertAlmostEqual (289.94 , sst_data [1 ])
100
+ self .assertAlmostEqual (289.89 , sst_data [2 ])
99
101
100
102
101
103
# noinspection PyUnresolvedReferences
@@ -129,7 +131,8 @@ def test_list_data_ids(self):
129
131
130
132
def test_get_data_opener_ids (self ):
131
133
store = self .get_store ()
132
- self .assertEqual (("dataset:zarr:reference" ,), store .get_data_opener_ids ())
134
+ self .assertEqual (("dataset:zarr:reference" ,),
135
+ store .get_data_opener_ids ())
133
136
134
137
def test_get_data_types (self ):
135
138
store = self .get_store ()
@@ -190,13 +193,15 @@ def test_search_data(self):
190
193
191
194
192
195
@unittest .skipUnless (has_kerchunk , reason = "kerchunk not installed" )
193
- class ReferenceDataStorePathsTest (ReferenceDataStoreTestBase , unittest .TestCase ):
196
+ class ReferenceDataStorePathsTest (ReferenceDataStoreTestBase ,
197
+ unittest .TestCase ):
194
198
def get_store (self ) -> DataStore :
195
199
return new_data_store ("reference" , refs = self .ref_paths )
196
200
197
201
198
202
@unittest .skipUnless (has_kerchunk , reason = "kerchunk not installed" )
199
- class ReferenceDataStoreDictsTest (ReferenceDataStoreTestBase , unittest .TestCase ):
203
+ class ReferenceDataStoreDictsTest (ReferenceDataStoreTestBase ,
204
+ unittest .TestCase ):
200
205
def get_store (self ) -> DataStore :
201
206
store = new_data_store ("reference" , refs = self .ref_paths )
202
207
refs = [dict (ref_path = ref_path ,
@@ -211,7 +216,8 @@ class NormalizeRefTest(unittest.TestCase):
211
216
def test_normalize_str (self ):
212
217
self .assertEqual (
213
218
('sst-cube' ,
214
- {'ref_path' : 'https://myrefs.com/sst-cube.json' , 'data_descriptor' : None }),
219
+ {'ref_path' : 'https://myrefs.com/sst-cube.json' ,
220
+ 'data_descriptor' : None }),
215
221
self .normalize_ref ("https://myrefs.com/sst-cube.json" )
216
222
)
217
223
@@ -240,18 +246,22 @@ def test_normalize_dict_with_data_descriptor(self):
240
246
"data_type" : "dataset"
241
247
}})
242
248
self .assertEqual ("sst-bibo" , data_id )
243
- self .assertEqual ("https://myrefs.com/sst-cube.json" , ref_dict .get ("ref_path" ))
244
- self .assertIsInstance (ref_dict .get ("data_descriptor" ), DatasetDescriptor )
249
+ self .assertEqual ("https://myrefs.com/sst-cube.json" ,
250
+ ref_dict .get ("ref_path" ))
251
+ self .assertIsInstance (ref_dict .get ("data_descriptor" ),
252
+ DatasetDescriptor )
245
253
self .assertEqual (
246
254
"sst-bibo" ,
247
255
ref_dict .get ("data_descriptor" ).data_id
248
256
)
249
257
250
258
def test_errors (self ):
251
- with pytest .raises (TypeError , match = "item in refs must be a str or a dict" ):
259
+ with pytest .raises (TypeError ,
260
+ match = "item in refs must be a str or a dict" ):
252
261
# noinspection PyTypeChecker
253
262
self .normalize_ref (13 )
254
- with pytest .raises (ValueError , match = "missing key ref_path in refs item" ):
263
+ with pytest .raises (ValueError ,
264
+ match = "missing key ref_path in refs item" ):
255
265
self .normalize_ref ({})
256
266
with pytest .raises (TypeError , match = ("value of data_descriptor key"
257
267
" in refs item must be a dict or None" )):
0 commit comments