diff --git a/centerline_width/pytests/test_errorGetCoordinatesKML.py b/centerline_width/pytests/test_errorGetCoordinatesKML.py index df0005e..05c351c 100644 --- a/centerline_width/pytests/test_errorGetCoordinatesKML.py +++ b/centerline_width/pytests/test_errorGetCoordinatesKML.py @@ -1,5 +1,7 @@ # Pytest for getCoordinatesKML.py # centerline-width/: python3 -m pytest -v +# python -m pytest -k test_errorGetCoordinatesKML -xv + import re # External Python libraries (installed via pip install) diff --git a/centerline_width/pytests/test_errorPlotDiagrams.py b/centerline_width/pytests/test_errorPlotDiagrams.py index 59f2bcd..94b5208 100644 --- a/centerline_width/pytests/test_errorPlotDiagrams.py +++ b/centerline_width/pytests/test_errorPlotDiagrams.py @@ -1,5 +1,7 @@ # Pytest for plotDiagram.py # centerline-width/: python -m pytest -v +# python -m pytest -k test_errorPlotDiagrams -xv + from io import StringIO import re diff --git a/centerline_width/pytests/test_errorPreprocessing.py b/centerline_width/pytests/test_errorPreprocessing.py index a3fa448..55a6137 100644 --- a/centerline_width/pytests/test_errorPreprocessing.py +++ b/centerline_width/pytests/test_errorPreprocessing.py @@ -1,5 +1,7 @@ # Pytest for preprocessing.py # centerline-width/: python -m pytest -v +# python -m pytest -k test_errorPreprocessing -xv + import re # External Python libraries (installed via pip install) diff --git a/centerline_width/pytests/test_errorRiverCenterlineClass.py b/centerline_width/pytests/test_errorRiverCenterlineClass.py index 04d5c8a..d19a8dc 100644 --- a/centerline_width/pytests/test_errorRiverCenterlineClass.py +++ b/centerline_width/pytests/test_errorRiverCenterlineClass.py @@ -1,5 +1,7 @@ # Pytest for riverCenterlineClass.py # centerline-width/: python -m pytest -v +# python -m pytest -k test_errorRiverCenterlineClass -xv + from io import StringIO import re diff --git a/centerline_width/pytests/test_errorRiverFeatures.py b/centerline_width/pytests/test_errorRiverFeatures.py new file mode 100644 index 0000000..df76808 --- /dev/null +++ b/centerline_width/pytests/test_errorRiverFeatures.py @@ -0,0 +1,188 @@ +# Pytest for riverFeatures.py +# centerline-width/: python -m pytest -v +# python -m pytest -k test_errorRiverFeatures -xv + +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 + +invalid_non_int_options = [("testing_string", ""), + (3.1415, ""), ([], ""), + (False, "")] + +invalid_non_str_options = [(1961, ""), + (3.1415, ""), ([], ""), + (False, "")] + + +def river_class_object(): + csv_example = StringIO() + csv_example.write("llat,llon,rlat,rlon\n") + csv_example.write( + "30.03758064742554,-92.86856870164003,30.03744106431763,-92.867475846432\n" + ) + csv_example.write( + "30.03761289873068,-92.86854932864129,30.03744779451432,-92.86747357248917\n" + ) + csv_example.write( + "30.03764767910492,-92.86854615646305,30.03748158510661,-92.86744912321454\n" + ) + csv_example.write( + "30.03767440933011,-92.86853555132092,30.03750644719021,-92.86743200196584\n" + ) + csv_example.write( + "30.03770236278642,-92.8685329553435,30.03752454918347,-92.86743019872145\n" + ) + csv_example.write( + "30.03772919351539,-92.86852225012414,30.0375426005056,-92.8674152219088\n" + ) + csv_example.write( + "30.0377490549762,-92.86851215967346,30.0375721590616,-92.8674007572212\n" + ) + csv_example.write( + "30.03778301480612,-92.86850070336355,30.03760885519144,-92.86738399853574\n" + ) + csv_example.write( + "30.03781601910584,-92.86848128471483,30.03763647218977,-92.86736152540908\n" + ) + csv_example.write( + "30.03784317873953,-92.86847053431235,30.0376710739572,-92.86733658820407\n" + ) + csv_example.write( + "30.03787040125924,-92.8684597471607,30.03771036353054,-92.86730115646196\n" + ) + csv_example.write( + "30.03790600092315,-92.86845640697538,30.0377475921359,-92.86728394049267\n" + ) + csv_example.write( + "30.0379404991904,-92.86844485391589,30.03778027570281,-92.86726385834064\n" + ) + csv_example.write( + "30.03796197755238,-92.86844283088163,30.03779189842327,-92.86725099533921\n" + ) + csv_example.write( + "30.03801823414788,-92.86842918514924,30.03782231186275,-92.86723594951347\n" + ) + csv_example.write( + "30.03804707600122,-92.8684264587786,30.03785992478739,-92.86721837516968\n" + ) + csv_example.write( + "30.03807720971334,-92.86843197572428,30.0378789421227,-92.86721621096019\n" + ) + csv_example.write( + "30.03811467808153,-92.86843682562265,30.03791228279507,-92.86720907194727\n" + ) + csv_example.write( + "30.03814498173742,-92.86844237100571,30.03794600661214,-92.86720200245374\n" + ) + csv_example.write( + "30.03817536147593,-92.8684479304092,30.03798495119786,-92.86719775057487\n" + ) + csv_example.write( + "30.03821313704282,-92.86845282481077,30.03800676992721,-92.86719028007494\n" + ) + csv_example.write( + "30.03825342965967,-92.86847428143609,30.03803846552586,-92.86718833685659\n" + ) + csv_example.write( + "30.03827667158946,-92.8684805380621,30.038070336302,-92.86718638873742\n" + ) + csv_example.write( + "30.03831604066361,-92.86849386447184,30.03810236991961,-92.8671844310125\n" + ) + csv_example.write( + "30.03834805225929,-92.8685078614063,30.03812214148239,-92.86718218364435\n" + ) + csv_example.write( + "30.03839386704537,-92.86851230357081,30.03816179178459,-92.86717763639089\n" + ) + csv_example.write( + "30.03841988914808,-92.86853539844006,30.03818675848181,-92.86717816057062\n" + ) + csv_example.write( + "30.03845220839587,-92.86854953231291,30.0382094597554,-92.86718407029464\n" + ) + csv_example.write( + "30.03849208414191,-92.86856303294287,30.03825237810393,-92.8671877169286\n" + ) + csv_example.seek(0) + return centerline_width.riverCenterline(csv_data=csv_example) + + +river_class_example = river_class_object() + + +## calculateIncrementalSinuosity() ##################################################### +def test_calculateIncrementalSinuosity_riverObjectRequired(): + with pytest.raises( + ValueError, + match=re.escape( + "[river_object]: Requires a river object (see: centerline_width.riverCenterline)" + )): + centerline_width.calculateIncrementalSinuosity(river_object=None) + + +@pytest.mark.parametrize("invalid_input, error_output", + invalid_non_int_options) +def test_calculateIncrementalSinuosity_InvalidTypeIncrementalPoints( + invalid_input, error_output): + with pytest.raises( + ValueError, + match=re.escape( + f"[incremental_points]: Must be a int, current type = '{error_output}'" + )): + centerline_width.calculateIncrementalSinuosity( + river_object=river_class_example, incremental_points=invalid_input) + + +def test_calculateIncrementalSinuosity_InvalidRangeIncrementalPoints(): + with pytest.raises( + ValueError, + match=re.escape( + f"[incremental_points]: Must be a positive value, greater than 0, currently = '0'" + )): + centerline_width.calculateIncrementalSinuosity( + river_object=river_class_example, incremental_points=0) + + +def test_calculateIncrementalSinuosity_InvalidRangeIncrementalPointsFromCenterpoints( +): + with pytest.raises( + ValueError, + match=re.escape( + f"[incremental_points]: length of centerline points must be greater than incremental_points, currently `{river_class_example.interpolate_n_centerpoints} < 100'" + )): + centerline_width.calculateIncrementalSinuosity( + river_object=river_class_example) + + +@pytest.mark.parametrize("invalid_input, error_output", + invalid_non_str_options) +def test_calculateIncrementalSinuosity_csvInvalidType(invalid_input, + error_output): + with pytest.raises( + ValueError, + match=re.escape( + f"[save_to_csv]: Must be a str, current type = '{error_output}'" + )): + centerline_width.calculateIncrementalSinuosity( + river_object=river_class_example, + incremental_points=20, + save_to_csv=invalid_input) + + +def test_calculateIncrementalSinuosity_csvRequired(): + with pytest.raises( + ValueError, + match=re.escape( + "[save_to_csv]: Extension must be a .csv file, current extension = 'txt'" + )): + centerline_width.calculateIncrementalSinuosity( + river_object=river_class_example, + incremental_points=20, + save_to_csv="filename.txt") diff --git a/centerline_width/pytests/test_errorSaveOutput.py b/centerline_width/pytests/test_errorSaveOutput.py index 4f93478..5f3abb7 100644 --- a/centerline_width/pytests/test_errorSaveOutput.py +++ b/centerline_width/pytests/test_errorSaveOutput.py @@ -1,5 +1,7 @@ -# Pytest for preprocessing.py +# Pytest for saveO.py # centerline-width/: python -m pytest -v +# python -m pytest -k test_errorSaveOutput -xv + from io import StringIO import re diff --git a/centerline_width/pytests/test_errorWidth.py b/centerline_width/pytests/test_errorWidth.py index a87371b..bb10129 100644 --- a/centerline_width/pytests/test_errorWidth.py +++ b/centerline_width/pytests/test_errorWidth.py @@ -1,5 +1,7 @@ # Pytest for centerline.py # centerline-width/: python -m pytest -v +# python -m pytest -k test_errorWidth -xv + from io import StringIO import re diff --git a/centerline_width/pytests/test_verifyGetCoordinatesKML.py b/centerline_width/pytests/test_verifyGetCoordinatesKML.py index 5ac3d3a..6a19815 100644 --- a/centerline_width/pytests/test_verifyGetCoordinatesKML.py +++ b/centerline_width/pytests/test_verifyGetCoordinatesKML.py @@ -1,4 +1,6 @@ # centerline-width/: python -m pytest -v +# python -m pytest -k test_verifyGetCoordinatesKML -xv + # Pytests to Compare and Verify Expected Outputs # External Python libraries (installed via pip install) diff --git a/centerline_width/pytests/test_verifyPlotDiagrams.py b/centerline_width/pytests/test_verifyPlotDiagrams.py index 03b0d40..25f037b 100644 --- a/centerline_width/pytests/test_verifyPlotDiagrams.py +++ b/centerline_width/pytests/test_verifyPlotDiagrams.py @@ -1,4 +1,6 @@ # centerline-width/: python -m pytest -v +# python -m pytest -k test_verifyPlotDiagrams-xv + # Pytests to Compare and Verify Expected Outputs from io import StringIO import os diff --git a/centerline_width/pytests/test_verifyPreprocessing.py b/centerline_width/pytests/test_verifyPreprocessing.py index 193b712..de06a68 100644 --- a/centerline_width/pytests/test_verifyPreprocessing.py +++ b/centerline_width/pytests/test_verifyPreprocessing.py @@ -1,4 +1,6 @@ # centerline-width/: python -m pytest -v +# python -m pytest -k test_verifyPreprocessing -xv + # Pytests to Compare and Verify Expected Outputs import re diff --git a/centerline_width/pytests/test_verifyRiverFeatures.py b/centerline_width/pytests/test_verifyRiverFeatures.py index 1fd67a4..49dd9df 100644 --- a/centerline_width/pytests/test_verifyRiverFeatures.py +++ b/centerline_width/pytests/test_verifyRiverFeatures.py @@ -1,4 +1,6 @@ # centerline-width/: python -m pytest -v +# python -m pytest -k test_verifyRiverFeatures -xv + # Pytests to Compare and Verify Expected Outputs from io import StringIO @@ -124,3 +126,18 @@ def test_riverCenterline_leftBankLength(): def test_riverCenterline_riverArea(): assert river_class_example.riverArea == pytest.approx(11.4030195647527) + + +def test_riverCenterline_riverSinuosity(): + assert river_class_example.riverSinuosity == pytest.approx( + 0.9877076848214962) + + +def test_riverCenterline_riverIncrementalSinuosity(): + assert river_class_example.calculateIncrementalSinuosity( + ) == pytest.approx({ + ((-92.86781591391708, 30.038216571334427), (-92.8678415323492, 30.037979489365142)): + 0.9858671625556824, + ((-92.86785143668344, 30.037954361467868), (-92.86793749224125, 30.03772716195012)): + 0.9997264563404605 + }) diff --git a/centerline_width/pytests/test_verifyWidth.py b/centerline_width/pytests/test_verifyWidth.py index b49dff1..0785221 100644 --- a/centerline_width/pytests/test_verifyWidth.py +++ b/centerline_width/pytests/test_verifyWidth.py @@ -1,4 +1,6 @@ # centerline-width/: python -m pytest -v +# python -m pytest -k test_verifyWidth -xv + # Pytests to Compare and Verify Expected Outputs from io import StringIO