Skip to content

Commit

Permalink
pytests for empty right/left banks
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Mar 26, 2024
1 parent dd4cebc commit 16db6d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
6 changes: 2 additions & 4 deletions centerline_width/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,9 @@ def generatePolygon(left_bank_lst,
recursion_check=False):
# Return a shapely polygon based on the position of the river bank points
if len(right_bank_lst) == 0:
logger.critical("\nCRITICAL ERROR, right bank data is empty (or NaN)")
exit()
raise ValueError("CRITICAL ERROR, right bank data is empty (or NaN)")
if len(left_bank_lst) == 0:
logger.critical("\nCRITICAL ERROR, left bank data is empty (or NaN)")
exit()
raise ValueError("\nCRITICAL ERROR, left bank data is empty (or NaN)")
circular_list_of_banks = left_bank_lst + right_bank_lst[::-1] + [
left_bank_lst[0]
]
Expand Down
34 changes: 34 additions & 0 deletions centerline_width/pytests/test_verifyPreprocessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# centerline-width/: python -m pytest -v
# Pytests to Compare and Verify Expected Outputs
from io import StringIO
import re

# External Python libraries (installed via pip install)
import pytest

# Internal centerline-width reference to access functions, global variables, and error handling
import centerline_width


def test_preprocessing_emptyRightBankCSV():
with pytest.raises(
ValueError,
match=re.escape(
"CRITICAL ERROR, right bank data is empty (or NaN)")):
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write("30.037581,-92.868569,,\n")
csv_example.seek(0)
centerline_width.riverCenterline(csv_data=csv_example)


def test_preprocessing_emptyLeftBankCSV():
with pytest.raises(
ValueError,
match=re.escape(
"CRITICAL ERROR, left bank data is empty (or NaN)")):
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write(",,30.037441,-92.867476\n")
csv_example.seek(0)
centerline_width.riverCenterline(csv_data=csv_example)
9 changes: 6 additions & 3 deletions centerline_width/relativeDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ def relativeSingleCoordinate(first_point, lat_lon_coord, ellipsoid):
def relativeBankCoordinates(left_lon_lat_coordinates,
right_lon_lat_coordinates, ellipsoid):
# Convert bank latitude/longtiude coordinates to relative coordinates
first_point = left_lon_lat_coordinates[
0] # first point is the first point on the left bank

if left_lon_lat_coordinates is None or right_lon_lat_coordinates is None:
return None, None
if len(left_lon_lat_coordinates) == 0 or len(
right_lon_lat_coordinates) == 0:
return None, None

first_point = left_lon_lat_coordinates[
0] # first point is the first point on the left bank

left_relative_coordinates = []
for left_point in left_lon_lat_coordinates:
Expand Down

0 comments on commit 16db6d9

Please sign in to comment.