Skip to content

Commit

Permalink
Test cases added and updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabhicusp committed Jun 29, 2023
1 parent d0d52e2 commit 38f9021
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions weather_mv/loader_pipeline/bq_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ class ExtractRowsTestBase(TestDataBase):

def extract(self, data_path, *, variables=None, area=None, open_dataset_kwargs=None,
import_time=DEFAULT_IMPORT_TIME, disable_grib_schema_normalization=False,
tif_metadata_for_datetime=None, zarr: bool = False, zarr_kwargs=None) -> t.Iterator[t.Dict]:
tif_metadata_for_datetime=None, zarr: bool = False, zarr_kwargs=None,
create_polygon: bool = True) -> t.Iterator[t.Dict]:
if zarr_kwargs is None:
zarr_kwargs = {}
op = ToBigQuery.from_kwargs(first_uri=data_path, dry_run=True, zarr=zarr, zarr_kwargs=zarr_kwargs,
Expand All @@ -209,7 +210,7 @@ def extract(self, data_path, *, variables=None, area=None, open_dataset_kwargs=N
infer_schema=False, tif_metadata_for_datetime=tif_metadata_for_datetime,
skip_region_validation=True,
disable_grib_schema_normalization=disable_grib_schema_normalization,
coordinate_chunk_size=1000)
coordinate_chunk_size=1000, create_polygon=create_polygon)
coords = op.prepare_coordinates(data_path)
for uri, chunk in coords:
yield from op.extract_rows(uri, chunk)
Expand Down Expand Up @@ -242,7 +243,7 @@ def setUp(self) -> None:
self.test_data_path = f'{self.test_data_folder}/test_data_20180101.nc'

def test_extract_rows(self):
actual = next(self.extract(self.test_data_path))
actual = next(self.extract(self.test_data_path, create_polygon=False))
expected = {
'd2m': 242.3035430908203,
'data_import_time': '1970-01-01T00:00:00+00:00',
Expand All @@ -254,10 +255,7 @@ def test_extract_rows(self):
'u10': 3.4776244163513184,
'v10': 0.03294110298156738,
'geo_point': geojson.dumps(geojson.Point((-108.0, 49.0))),
'geo_polygon': geojson.dumps(geojson.Polygon([
(-108.099174, 48.900826), (-107.900826, 48.900826),
(-107.900826, 49.099174), (-108.099174, 49.099174),
(-108.099174, 48.900826)]))
'geo_polygon': None
}
self.assertRowsEqual(actual, expected)

Expand All @@ -280,7 +278,8 @@ def test_extract_rows__with_subset_variables(self):
self.assertRowsEqual(actual, expected)

def test_extract_rows__specific_area(self):
actual = next(self.extract(self.test_data_path, area=[45, -103, 33, -92]))
actual = next(self.extract(self.test_data_path, area=[45, -103, 33, -92], create_polygon=False))
print("actual is here",actual)
expected = {
'd2m': 246.19993591308594,
'data_import_time': '1970-01-01T00:00:00+00:00',
Expand All @@ -292,10 +291,7 @@ def test_extract_rows__specific_area(self):
'u10': 2.73445987701416,
'v10': 0.08277571201324463,
'geo_point': geojson.dumps(geojson.Point((-103.0, 45.0))),
'geo_polygon': geojson.dumps(geojson.Polygon([
(-103.099174, 44.900826), (-102.900826, 44.900826),
(-102.900826, 45.099174), (-103.099174, 45.099174),
(-103.099174, 44.900826)]))
'geo_polygon': None
}
self.assertRowsEqual(actual, expected)

Expand Down Expand Up @@ -380,8 +376,8 @@ def test_extract_rows_nan(self):
self.assertRowsEqual(actual, expected)

def test_extract_rows__with_valid_lat_long(self):
valid_lat_long = [[-90, -360], [-90, -359], [-45, -180], [-45, -45], [0, 0], [45, 45], [45, 180], [90, 359],
[90, 360]]
valid_lat_long = [[-90, 0], [-90, 1], [-45, -180], [-45, -45], [0, 0], [45, 45], [45, -180], [90, -1],
[90, 0]]
actual_val = [
'{"type": "Point", "coordinates": [0, -90]}',
'{"type": "Point", "coordinates": [1, -90]}',
Expand Down

0 comments on commit 38f9021

Please sign in to comment.