Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
269 kb empty local data sources (#334)
Browse files Browse the repository at this point in the history
* #218, #269, #317 do not create empty datasources

* #218, #269, #317 do not create empty datasources, added tests

* #218, #269, #317 upadated make_local method signature
  • Loading branch information
kbernat authored Aug 24, 2017
1 parent 387218b commit bd92761
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cate/core/ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def make_local(self,
time_range: TimeRangeLike.TYPE = None,
region: PolygonLike.TYPE = None,
var_names: VarNamesLike.TYPE = None,
monitor: Monitor = Monitor.NONE) -> 'DataSource':
monitor: Monitor = Monitor.NONE) -> Optional['DataSource']:
"""
Turns this (likely remote) data source into a local data source given a name and a number of
optional constraints.
Expand Down
2 changes: 1 addition & 1 deletion cate/ds/esa_cci_odp.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def make_local(self,
time_range: TimeRangeLike.TYPE = None,
region: PolygonLike.TYPE = None,
var_names: VarNamesLike.TYPE = None,
monitor: Monitor = Monitor.NONE) -> 'DataSource':
monitor: Monitor = Monitor.NONE) -> Optional[DataSource]:
if not local_name:
raise ValueError('local_name is required')
elif len(local_name) == 0:
Expand Down
2 changes: 1 addition & 1 deletion cate/ds/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def make_local(self,
time_range: TimeRangeLike.TYPE = None,
region: PolygonLike.TYPE = None,
var_names: VarNamesLike.TYPE = None,
monitor: Monitor = Monitor.NONE) -> 'DataSource':
monitor: Monitor = Monitor.NONE) -> Optional[DataSource]:
if not local_name:
raise ValueError('local_name is required')
elif len(local_name) == 0:
Expand Down
3 changes: 3 additions & 0 deletions test/ds/test_esa_cci_odp.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def build_file_item(item_name: str, date_from: datetime, date_to: datetime, size
datetime.datetime(1978, 11, 15, 23, 59)))
except:
raise ValueError(reference_path, os.listdir(reference_path))
self.assertIsNotNone(new_ds)

self.assertEqual(new_ds.id, 'local.local_ds_test')
self.assertEqual(new_ds.temporal_coverage(),
Expand All @@ -156,6 +157,7 @@ def build_file_item(item_name: str, date_from: datetime, date_to: datetime, size
new_ds_w_one_variable = self.first_oc_data_source.make_local(
'local_ds_test_2', None, (datetime.datetime(1978, 11, 14, 0, 0),
datetime.datetime(1978, 11, 15, 23, 59)), None, ['sm'])
self.assertIsNotNone(new_ds_w_one_variable)
self.assertEqual(new_ds_w_one_variable.id, 'local.local_ds_test_2')
ds = new_ds_w_one_variable.open_dataset()
self.assertSetEqual(set(ds.variables), {'sm', 'lat', 'lon', 'time'})
Expand All @@ -164,6 +166,7 @@ def build_file_item(item_name: str, date_from: datetime, date_to: datetime, size
'from_local_to_local_region', None, (datetime.datetime(1978, 11, 14, 0, 0),
datetime.datetime(1978, 11, 15, 23, 59)),
"10,10,20,20", ['sm']) # type: LocalDataSource
self.assertIsNotNone(new_ds_w_region)
self.assertEqual(new_ds_w_region.id, 'local.from_local_to_local_region')
self.assertEqual(new_ds_w_region.spatial_coverage(), PolygonLike.convert("10,10,20,20"))
data_set = new_ds_w_region.open_dataset()
Expand Down
3 changes: 3 additions & 0 deletions test/ds/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def test_make_local(self):
new_ds = data_source.make_local('from_local_to_local', None,
(datetime.datetime(1978, 11, 14, 0, 0),
datetime.datetime(1978, 11, 15, 23, 59)))
self.assertIsNotNone(new_ds)
self.assertEqual(new_ds.id, 'local.from_local_to_local')
self.assertEqual(new_ds.temporal_coverage(), TimeRangeLike.convert(
(datetime.datetime(1978, 11, 14, 0, 0),
Expand All @@ -269,6 +270,7 @@ def test_make_local(self):
(datetime.datetime(1978, 11, 14, 0, 0),
datetime.datetime(1978, 11, 15, 23, 59)),
None, ['sm'])
self.assertIsNotNone(new_ds_w_one_variable)
self.assertEqual(new_ds_w_one_variable.id, 'local.from_local_to_local_var')
data_set = new_ds_w_one_variable.open_dataset()
self.assertSetEqual(set(data_set.variables), {'sm', 'lat', 'lon', 'time'})
Expand All @@ -277,6 +279,7 @@ def test_make_local(self):
(datetime.datetime(1978, 11, 14, 0, 0),
datetime.datetime(1978, 11, 15, 23, 59)),
"10,10,20,20", ['sm']) # type: LocalDataSource
self.assertIsNotNone(new_ds_w_region)
self.assertEqual(new_ds_w_region.id, 'local.from_local_to_local_region')
self.assertEqual(new_ds_w_region.spatial_coverage(), PolygonLike.convert("10,10,20,20"))
data_set = new_ds_w_region.open_dataset()
Expand Down

0 comments on commit bd92761

Please sign in to comment.