-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ba70d4
commit 5cd6815
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import polars as pl | ||
import pytest | ||
import os | ||
import sys | ||
import pyarrow | ||
|
||
class TestExceptions: | ||
def test_incorrect_grib_filePath(self, resource): | ||
import gribtoarrow | ||
|
||
with pytest.raises(gribtoarrow.NoSuchGribFileException): | ||
gribtoarrow.GribReader(str(resource) + "/NOFILEPRESENT.grb") | ||
|
||
def test_incorrect_locations_filePath(self, resource): | ||
import gribtoarrow | ||
|
||
with pytest.raises(gribtoarrow.NoSuchLocationsFileException): | ||
gribtoarrow.GribReader(str(resource) + "/norway.grb").withLocations(str(resource) + "/NOLOCATIONSFILE.csv") | ||
|
||
def test_invalid_csv_filePath(self, resource): | ||
import gribtoarrow | ||
|
||
with pytest.raises(gribtoarrow.InvalidCSVException): | ||
gribtoarrow.GribReader(str(resource) + "/norway.grb").withLocations(str(resource) + "/badfile.csv") | ||
|
||
def test_incorrect_conversion_cols(self, resource): | ||
import gribtoarrow | ||
|
||
conversions = ( | ||
pl.DataFrame( | ||
{ | ||
"parameterId": [167], | ||
"addition_value": [None], | ||
"subtraction_value": [None], | ||
} | ||
) | ||
).to_arrow() | ||
|
||
with pytest.raises(gribtoarrow.InvalidSchemaException): | ||
( | ||
gribtoarrow.GribReader(f"{resource}{os.sep}gep01.t00z.pgrb2a.0p50.f003") | ||
.withConversions(conversions) | ||
) | ||
|
||
def test_arrow_table_wrong_ctypes(self, resource): | ||
import gribtoarrow | ||
|
||
conversions = ( | ||
pl.DataFrame( | ||
{ | ||
"parameterId": [167], | ||
"addition_value": ["hugo pendlebury"], | ||
"subtraction_value": [1], | ||
"multiplication_value": [1.1], | ||
"division_value": ["fred"], | ||
} | ||
) | ||
).to_arrow() | ||
|
||
with pytest.raises(gribtoarrow.InvalidSchemaException): | ||
( | ||
gribtoarrow.GribReader(f"{resource}{os.sep}gep01.t00z.pgrb2a.0p50.f003") | ||
.withConversions(conversions) | ||
) | ||
|
||
|
||
def test_incorrect_missing_csv_conversion_cols(self, resource): | ||
import gribtoarrow | ||
csv_file = "__TEST__MISSING_CONVERSION_COL.csv" | ||
pl.DataFrame( | ||
{ | ||
"parameterId": [167], | ||
"addition_value": [None], | ||
"subtraction_value": [None], | ||
} | ||
).write_csv(str(resource) + csv_file) | ||
|
||
|
||
with pytest.raises(gribtoarrow.InvalidSchemaException): | ||
( | ||
gribtoarrow.GribReader(f"{resource}{os.sep}gep01.t00z.pgrb2a.0p50.f003") | ||
.withConversions(str(resource) + csv_file) | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
location_id,lat,lon,location_name | ||
1,58.1599,8.0182,kristiansand | ||
2,60.3913,5.3221,Bergen |