Skip to content

Commit

Permalink
expand testing for txt_to_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck committed Aug 21, 2024
1 parent 564a31a commit 18250d7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 6 deletions.
2 changes: 1 addition & 1 deletion centerline_width/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions centerline_width/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions centerline_width/getCoordinatesKML.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
39 changes: 39 additions & 0 deletions centerline_width/pytests/test_errorGetCoordinatesKML.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
94 changes: 94 additions & 0 deletions centerline_width/pytests/test_verifyGetCoordinatesKML.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 18250d7

Please sign in to comment.