Skip to content

Commit

Permalink
f string format for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Jan 20, 2024
1 parent c105f00 commit 42c5127
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 74 deletions.
43 changes: 6 additions & 37 deletions centerline_width/pytests/test_centerline.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ def test_riverWidthFromCenterline_riverObjectInvalidTypes(invalid_input, error_o

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_int_options)
def test_riverWidthFromCenterline_transectSpanDistanceInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[transect_span_distance]: Must be a int, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[transect_span_distance]: Must be a int, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
transect_span_distance=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_riverWidthFromCenterline_applySmoothingInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[apply_smoothing]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[apply_smoothing]: Must be a bool, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
apply_smoothing=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_riverWidthFromCenterline_removeIntersectionsInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[remove_intersections]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[remove_intersections]: Must be a bool, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
remove_intersections=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_riverWidthFromCenterline_saveToCSVInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[save_to_csv]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[save_to_csv]: Must be a str, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
save_to_csv=invalid_input)

Expand All @@ -87,43 +87,12 @@ def test_riverWidthFromCenterline_coordinateUnitInvalidOption():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_riverWidthFromCenterline_coordinateUnitInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[coordinate_unit]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[coordinate_unit]: Must be a str, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
coordinate_unit=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_riverWidthFromCenterline_coordinateReferenceInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[coordinate_reference]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[coordinate_reference]: Must be a str, current type = '{error_output}'")):
centerline_width.riverWidthFromCenterline(river_object=river_class_example,
coordinate_reference=invalid_input)

## Very Output
def test_riverCenterline_centerlineLength():
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write("48.286399957085024,-4.259939230629442,48.28244110043403,-4.255739731090472\n")
csv_example.write("48.28500274859866,-4.2625639178417885,48.280578002893776,-4.2602891889242755\n")
csv_example.write("48.283954817150175,-4.265713542496371,48.28011221789134,-4.265888521643745\n")
csv_example.write("48.283954817150175,-4.26833822970741,48.28011221789134,-4.2711378960671595\n")
csv_example.write("48.28558492344624,-4.271312875214591,48.28244110043403,-4.276212291343171\n")
csv_example.write("48.287447838366376,-4.27393756242688,48.28581779152722,-4.278836978555489\n")
csv_example.seek(0)
test_river = centerline_width.riverCenterline(csv_data=csv_example)
assert test_river.centerlineLength == 1.3534252753108382

def test_riverWidthFromCenterline():
csv_example = StringIO()
csv_example.write("llat,llon,rlat,rlon\n")
csv_example.write("48.286399957085024,-4.259939230629442,48.28244110043403,-4.255739731090472\n")
csv_example.write("48.28500274859866,-4.2625639178417885,48.280578002893776,-4.2602891889242755\n")
csv_example.write("48.283954817150175,-4.265713542496371,48.28011221789134,-4.265888521643745\n")
csv_example.write("48.283954817150175,-4.26833822970741,48.28011221789134,-4.2711378960671595\n")
csv_example.write("48.28558492344624,-4.271312875214591,48.28244110043403,-4.276212291343171\n")
csv_example.write("48.287447838366376,-4.27393756242688,48.28581779152722,-4.278836978555489\n")
csv_example.seek(0)
test_river = centerline_width.riverCenterline(csv_data=csv_example)
river_width_dict = test_river.riverWidthFromCenterline()
assert river_width_dict == {
(-4.271614588856146, 48.282642262514564): 0.5026142454914809,
(-4.2628112256127935, 48.282290840533314): 0.4835174179290038,
}
6 changes: 3 additions & 3 deletions centerline_width/pytests/test_getCoordinatesKML.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_extractPointsToTextFile_leftKMLRequired():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_leftKMLInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[left_kml]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[left_kml]: Must be a str, current type = '{error_output}'")):
centerline_width.extractPointsToTextFile(left_kml=invalid_input)

def test_extractPointsToTextFile_leftKMLInvalidExtension():
Expand All @@ -33,7 +33,7 @@ def test_extractPointsToTextFile_rightKMLRequired():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_rightKMLInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[right_kml]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[right_kml]: Must be a str, current type = '{error_output}'")):
centerline_width.extractPointsToTextFile(left_kml="left_kml.kml", right_kml=invalid_input)

def test_extractPointsToTextFile_rightKMLInvalidExtension():
Expand All @@ -46,7 +46,7 @@ def test_extractPointsToTextFile_textOutputNameRequired():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_textOutputNameInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[text_output_name]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[text_output_name]: Must be a str, current type = '{error_output}'")):
centerline_width.extractPointsToTextFile(left_kml="left_kml.kml", right_kml="right_kml.kml", text_output_name=invalid_input)

def test_extractPointsToTextFile_rightAndLeftKMLMatchInvalid():
Expand Down
36 changes: 18 additions & 18 deletions centerline_width/pytests/test_plotDiagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_plotCenterline_riverObjectInvalidTypes(invalid_input, error_output):

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_centerlineTypeInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[centerline_type]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[centerline_type]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
centerline_type=invalid_input)

Expand All @@ -65,7 +65,7 @@ def test_plotCenterline_centerlineTypeInvalidOption():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_markerTypeInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[marker_type]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[marker_type]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
marker_type=invalid_input)

Expand All @@ -76,37 +76,37 @@ def test_plotCenterline_markerTypeInvalidOption():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_centerlineColorInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[centerline_color]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[centerline_color]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
centerline_color=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_darkModeInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[dark_mode]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[dark_mode]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
dark_mode=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_displayAllPossiblePathsInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[display_all_possible_paths]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[display_all_possible_paths]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
display_all_possible_paths=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_plotTitleInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[plot_title]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[plot_title]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
plot_title=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_savePlotNameInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[save_plot_name]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[save_plot_name]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
save_plot_name=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterline_displayVoronoiInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[display_voronoi]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[display_voronoi]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
display_voronoi=invalid_input)

Expand All @@ -117,7 +117,7 @@ def test_plotCenterline_coordinateUnitInvalidOption():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterline_coordinateUnitInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[coordinate_unit]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[coordinate_unit]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterline(river_object=river_class_example,
coordinate_unit=invalid_input)

Expand All @@ -133,49 +133,49 @@ def test_plotCenterlineWidth_riverObjectInvalidTypes(invalid_input, error_output

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterlineWidth_plotTitleInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[plot_title]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[plot_title]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
plot_title=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterlineWidth_savePlotNameInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[save_plot_name]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[save_plot_name]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
save_plot_name=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterlineWidth_displayTrueCenterlineInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[display_true_centerline]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[display_true_centerline]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
display_true_centerline=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_int_options)
def test_plotCenterlineWidth_transectSpanDistanceInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[transect_span_distance]: Must be a int, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[transect_span_distance]: Must be a int, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
transect_span_distance=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterlineWidth_applySmoothingInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[apply_smoothing]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[apply_smoothing]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
apply_smoothing=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterlineWidth_flagIntersectionsInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[flag_intersections]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[flag_intersections]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
flag_intersections=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterlineWidth_removeIntersectionsInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[remove_intersections]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[remove_intersections]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
remove_intersections=invalid_input)

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_plotCenterlineWidth_darkModeInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[dark_mode]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[dark_mode]: Must be a bool, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
dark_mode=invalid_input)

Expand All @@ -186,6 +186,6 @@ def test_plotCenterlineWidth_coordinateUnitInvalidOption():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_plotCenterlineWidth_coordinateUnitInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[coordinate_unit]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[coordinate_unit]: Must be a str, current type = '{error_output}'")):
centerline_width.plotCenterlineWidth(river_object=river_class_example,
coordinate_unit=invalid_input)
4 changes: 2 additions & 2 deletions centerline_width/pytests/test_preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test_convertColumnsToCSV_textFileRequired():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_str_options)
def test_convertColumnsToCSV_textFileInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[text_file]: Must be a str, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[text_file]: Must be a str, current type = '{error_output}'")):
centerline_width.convertColumnsToCSV(text_file=invalid_input)

def test_convertColumnsToCSV_textFileInvalidExtensions():
Expand All @@ -34,5 +34,5 @@ def test_convertColumnsToCSV_textFileInvalidExtensions():

@pytest.mark.parametrize("invalid_input, error_output", invalid_non_bool_options)
def test_convertColumnsToCSV_flipBankDirectionInvalidTypes(invalid_input, error_output):
with pytest.raises(ValueError, match=re.escape("[flipBankDirection]: Must be a bool, current type = '{0}'".format(error_output))):
with pytest.raises(ValueError, match=re.escape(f"[flipBankDirection]: Must be a bool, current type = '{error_output}'")):
centerline_width.convertColumnsToCSV(text_file="text_file.txt", flipBankDirection=invalid_input)
Loading

0 comments on commit 42c5127

Please sign in to comment.