diff --git a/centerline_width/__init__.py b/centerline_width/__init__.py index 69405c9..923d43f 100644 --- a/centerline_width/__init__.py +++ b/centerline_width/__init__.py @@ -52,7 +52,7 @@ from .channelMigration import centerlineMigrationRate # error_handling.py function calls -from .error_handling import errrorHandlingConvertColumnsToCSV +from .error_handling import errrorHandlingTxtToCSV from .error_handling import errorHandlingPlotCenterline from .error_handling import errorHandlingPlotCenterlineWidth from .error_handling import errorHandlingWidth diff --git a/centerline_width/error_handling.py b/centerline_width/error_handling.py index cec0f85..deca5ba 100644 --- a/centerline_width/error_handling.py +++ b/centerline_width/error_handling.py @@ -445,9 +445,9 @@ def errorHandlingSaveCenterlineMAT( # Error Handling: getCoordinatesKML.py -def errrorHandlingConvertColumnsToCSV(txt_input: str = None, - flip_direction: bool = None) -> None: - # Error handling for convertColumnsToCSV() +def errrorHandlingTxtToCSV(txt_input: str = None, + flip_direction: bool = None) -> None: + # Error handling for txt_to_csv() if txt_input is None: raise ValueError("[txt_input]: Requires text file") else: diff --git a/centerline_width/getCoordinatesKML.py b/centerline_width/getCoordinatesKML.py index 72f5e5f..4c83678 100644 --- a/centerline_width/getCoordinatesKML.py +++ b/centerline_width/getCoordinatesKML.py @@ -133,8 +133,8 @@ def txt_to_csv(txt_input: str = None, stacklevel=2) txt_input = text_file - centerline_width.errrorHandlingConvertColumnsToCSV( - txt_input=txt_input, flip_direction=flip_direction) + centerline_width.errrorHandlingTxtToCSV(txt_input=txt_input, + flip_direction=flip_direction) left_rows = [] right_rows = [] diff --git a/centerline_width/pytests/test_errorGetCoordinatesKML.py b/centerline_width/pytests/test_errorGetCoordinatesKML.py index cc6d29b..0ee5226 100644 --- a/centerline_width/pytests/test_errorGetCoordinatesKML.py +++ b/centerline_width/pytests/test_errorGetCoordinatesKML.py @@ -157,3 +157,42 @@ def test_kmlToCSV_flipDirectionInvalidTypes(invalid_input, error_output): left_kml="left_kml.kml", right_kml="right_kml.kml", flip_direction=invalid_input) + + +## txt_to_csv() ##################################################### +def test_txtToCSV_txtInputRequired(): + with pytest.raises(ValueError, + match=re.escape("[txt_input]: Requires text file")): + centerline_width.txt_to_csv(txt_input=None) + + +@pytest.mark.parametrize("invalid_input, error_output", + invalid_non_str_options) +def test_txtToCSV_txtInputInvalidTypes(invalid_input, error_output): + with pytest.raises( + ValueError, + match=re.escape( + f"[txt_input]: Must be a str, current type = '{error_output}'") + ): + centerline_width.txt_to_csv(txt_input=invalid_input) + + +def test_txtToCSV_textFileInvalidExtensions(): + with pytest.raises( + ValueError, + match=re.escape( + "[txt_input]: Extension must be a .txt file, current extension = 'csv'" + )): + centerline_width.txt_to_csv(txt_input="csv_file.csv") + + +@pytest.mark.parametrize("invalid_input, error_output", + invalid_non_bool_options) +def test_txtToCSV_flipDirectionInvalidTypes(invalid_input, error_output): + with pytest.raises( + ValueError, + match=re.escape( + f"[flip_direction]: Must be a bool, current type = '{error_output}'" + )): + centerline_width.txt_to_csv(txt_input="text_file.txt", + flip_direction=invalid_input) diff --git a/centerline_width/pytests/test_verifyGetCoordinatesKML.py b/centerline_width/pytests/test_verifyGetCoordinatesKML.py index 5c48054..174dd0a 100644 --- a/centerline_width/pytests/test_verifyGetCoordinatesKML.py +++ b/centerline_width/pytests/test_verifyGetCoordinatesKML.py @@ -199,6 +199,100 @@ def test_getCoordinatesKML_extractPointsToCSV(generate_kmlFile): assert list(expected_df["rlon"]) == list(kml_output_df["rlon"]) +def test_kmlToCSV_futureWarning_functionName(tmpdir, generate_kmlFile_right, + generate_kmlFile_left): + # Pending Deprecation: To Be Removed + with pytest.warns( + FutureWarning, + match=re.escape( + "extractPointsToTextFile() has been replaced with kml_to_csv() and will be removed in the future" + )): + + temp_csv_file = tmpdir.join("pytest.csv") + centerline_width.extractPointsToTextFile( + left_kml=str(generate_kmlFile_left), + right_kml=str(generate_kmlFile_right), + csv_output=str(temp_csv_file)) + expected_df = pd.DataFrame({ + 'llat': [ + 30.03758064742554, 30.03761289873068, 30.03764767910492, + 30.03767440933011, 30.03770236278642, 30.03772919351539, + 30.0377490549762, 30.03778301480612, 30.03781601910584, + 30.03784317873953 + ], + 'llon': [ + -92.86856870164004, -92.86854932864128, -92.86854615646304, + -92.86853555132092, -92.8685329553435, -92.86852225012414, + -92.86851215967346, -92.86850070336357, -92.86848128471485, + -92.86847053431237 + ], + 'rlat': [ + 30.03758064742554, 30.03761289873068, 30.03764767910492, + 30.03767440933011, 30.03770236278642, 30.03772919351539, + 30.0377490549762, 30.03778301480612, 30.03781601910584, + 30.03784317873953 + ], + 'rlon': [ + -92.86856870164004, -92.86854932864128, -92.86854615646304, + -92.86853555132092, -92.8685329553435, -92.86852225012414, + -92.86851215967346, -92.86850070336357, -92.86848128471485, + -92.86847053431237 + ] + }) + kml_output_df = pd.read_csv(temp_csv_file) + assert expected_df.columns.tolist() == kml_output_df.columns.tolist() + assert list(expected_df["llat"]) == list(kml_output_df["llat"]) + assert list(expected_df["llon"]) == list(kml_output_df["llon"]) + assert list(expected_df["rlat"]) == list(kml_output_df["rlat"]) + assert list(expected_df["rlon"]) == list(kml_output_df["rlon"]) + + +def test_kmlToCSV_futureWarning_variableName(tmpdir, generate_kmlFile_right, + generate_kmlFile_left): + # Pending Deprecation: To Be Removed + with pytest.warns( + FutureWarning, + match=re.escape( + "text_output_name has been replaced with txt_to_csv() function and will be removed in the future" + )): + temp_txt_file = tmpdir.join("pytest.txt") + centerline_width.kml_to_csv(left_kml=str(generate_kmlFile_left), + right_kml=str(generate_kmlFile_right), + text_output_name=str(temp_txt_file)) + expected_df = pd.DataFrame({ + 'llat': [ + 30.03758064742554, 30.03761289873068, 30.03764767910492, + 30.03767440933011, 30.03770236278642, 30.03772919351539, + 30.0377490549762, 30.03778301480612, 30.03781601910584, + 30.03784317873953 + ], + 'llon': [ + -92.86856870164004, -92.86854932864128, -92.86854615646304, + -92.86853555132092, -92.8685329553435, -92.86852225012414, + -92.86851215967346, -92.86850070336357, -92.86848128471485, + -92.86847053431237 + ], + 'rlat': [ + 30.03758064742554, 30.03761289873068, 30.03764767910492, + 30.03767440933011, 30.03770236278642, 30.03772919351539, + 30.0377490549762, 30.03778301480612, 30.03781601910584, + 30.03784317873953 + ], + 'rlon': [ + -92.86856870164004, -92.86854932864128, -92.86854615646304, + -92.86853555132092, -92.8685329553435, -92.86852225012414, + -92.86851215967346, -92.86850070336357, -92.86848128471485, + -92.86847053431237 + ] + }) + kml_output_df = pd.read_csv(temp_txt_file, sep='\\s+') + assert expected_df.columns.tolist() == kml_output_df.columns.tolist() + assert list(expected_df["llat"]) == list(kml_output_df["llat"]) + assert list(expected_df["llon"]) == list(kml_output_df["llon"]) + assert list(expected_df["rlat"]) == list(kml_output_df["rlat"]) + assert list(expected_df["rlon"]) == list(kml_output_df["rlon"]) + + def test_txtToCSV_futureWarning_functionName(tmpdir): # Pending Deprecation: To Be Removed with pytest.warns(