示例#1
0
 def test_bad_dimensions_types(self):
     with pytest.raises(TypeError, match=r'.* type for `dimensions` .*'):
         _ = io.DictionaryIO(self.dict_np, dimensions=(3, 4, 5))
     with pytest.raises(TypeError, match=r'.* type for `dimensions` .*'):
         _ = io.DictionaryIO(self.dict_np, dimensions=1)
     with pytest.raises(TypeError, match=r'.* type for `dimensions` .*'):
         _ = io.DictionaryIO(self.dict_np, dimensions='string')
     with pytest.raises(TypeError, match=r'.* type for `dimensions` .*'):
         _ = io.DictionaryIO(self.dict_np, dimensions=['list', 'string'])
示例#2
0
 def test_not_implemented_methods(self):
     dict_io = io.DictionaryIO(self.dict_xr)
     with pytest.raises(NotImplementedError):
         dict_io.connect()
     with pytest.raises(NotImplementedError):
         dict_io.read()
     with pytest.raises(NotImplementedError):
         dict_io.write()
示例#3
0
 def test_bad_dimensions_shape_mismatch(self):
     with pytest.raises(ValueError, match=r'Shape of `dimensions` .*'):
         # note dim2 and dim1 are switchd below!
         _ = dict_io = io.DictionaryIO(self.dict_np,
                                       dimensions={
                                           'time':
                                           np.arange(self._shape[0]),
                                           'x': np.arange(self._shape[2]),
                                           'y': np.arange(self._shape[1])
                                       })
示例#4
0
 def test_create_from_numpy_data_dimensions(self):
     dict_io = io.DictionaryIO(self.dict_np,
                               dimensions={
                                   'time': np.arange(self._shape[0]),
                                   'x': np.arange(self._shape[1]),
                                   'y': np.arange(self._shape[2])
                               })
     assert ('eta' in dict_io._in_memory_data.keys()) is True
     assert ('velocity' in dict_io._in_memory_data.keys()) is True
     assert isinstance(dict_io['eta'], np.ndarray)
     assert isinstance(dict_io['time'], np.ndarray)
     assert isinstance(dict_io['x'], np.ndarray)
     assert isinstance(dict_io['y'], np.ndarray)
     assert np.all(dict_io['eta'] == self.dict_np['eta'])
示例#5
0
 def test_bad_dimensions_length(self):
     with pytest.raises(ValueError, match=r'`dimensions` must .*'):
         _ = io.DictionaryIO(self.dict_np, dimensions={})
示例#6
0
 def test_create_from_numpy_data_nodims(self):
     dict_io = io.DictionaryIO(self.dict_np)
     assert ('eta' in dict_io._in_memory_data.keys()) is True
     assert ('velocity' in dict_io._in_memory_data.keys()) is True
     assert isinstance(dict_io['eta'], np.ndarray)
     assert isinstance(dict_io['dim0'], np.ndarray)
示例#7
0
 def test_dimensions_ignored_if_xarray(self):
     dict_io = io.DictionaryIO(self.dict_xr, dimensions=(3, 4, 5))
     assert ('eta' in dict_io._in_memory_data.keys()) is True
     assert isinstance(dict_io['eta'], xr.core.dataarray.DataArray)
示例#8
0
 def test_create_from_xarray_data(self):
     dict_io = io.DictionaryIO(self.dict_xr)
     assert ('eta' in dict_io._in_memory_data.keys()) is True
     assert isinstance(dict_io['eta'], xr.core.dataarray.DataArray)