Skip to content

Commit

Permalink
validation
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopendlebury committed Jan 31, 2024
1 parent 2ba70d4 commit 5cd6815
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
85 changes: 85 additions & 0 deletions tests/test_exceptions.py
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)
)


3 changes: 3 additions & 0 deletions tests/test_locations.csv
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

0 comments on commit 5cd6815

Please sign in to comment.