Skip to content

Commit

Permalink
style: make the outputs a bit more legible and descriptive
Browse files Browse the repository at this point in the history
  • Loading branch information
Osneil Drakes authored and Osneil Drakes committed Sep 11, 2024
1 parent 6005e23 commit c65278c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 6 additions & 4 deletions gcf_data_mapper/parsers/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def calculate_status(row: pd.Series) -> Optional[str]:
approved_date = pd.to_datetime(row.at[Events.APPROVED.column_name])

if contains_invalid_date_entries([completed_date, start_date, approved_date]):
click.echo("🛑 Row contains invalid date entries")
click.echo("- Row contains invalid date entries")
return None

now = pd.Timestamp.now(tz="UTC")
Expand All @@ -53,7 +53,7 @@ def calculate_status(row: pd.Series) -> Optional[str]:
if pd.notna(approved_date) and now >= approved_date:
return Events.APPROVED.type

click.echo("🛑 Row missing event date information to calculate status")
click.echo("- Row missing event date information to calculate status")
return None


Expand Down Expand Up @@ -166,16 +166,18 @@ def map_family_data(
"""

family_metadata = map_family_metadata(row)
projects_id = row.at[FamilyColumnsNames.PROJECTS_ID.value]

# When processing the family metadata if there are any empty/falsy values we return None
# and skip the row. Therefore we don't want to process the rest of the family data so we
# return None in this conditional.
if family_metadata is None:
click.echo("🛑 Skipping row as family metadata has missing information")
click.echo(
f"🛑 Skipping row as family metadata has missing information, see ProjectsID : {projects_id}"
)
return None

approved_ref = row.at[FamilyColumnsNames.APPROVED_REF.value]
projects_id = row.at[FamilyColumnsNames.PROJECTS_ID.value]
summary = row.at[FamilyColumnsNames.SUMMARY.value]
title = row.at[FamilyColumnsNames.TITLE.value]

Expand Down
6 changes: 4 additions & 2 deletions tests/unit_tests/parsers/family/test_map_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,17 @@ def test_skips_processing_row_if_row_contains_empty_values(


def test_skips_processing_row_if_family_metadata_has_missing_data(
mock_family_row_no_result_areas, capsys
mock_family_row_no_result_areas: pd.Series, capsys
):
projects_id = mock_family_row_no_result_areas.ProjectsID

family_data = map_family_data(mock_family_row_no_result_areas)
assert family_data is None
captured = capsys.readouterr()
# We have two outputs, one from map_family_metadata pointing to the missing data and the second
# from map_family_data informing that the row is being skipped
map_family_data_output = captured.out.strip().split("\n")
assert (
"🛑 Skipping row as family metadata has missing information"
f"🛑 Skipping row as family metadata has missing information, see ProjectsID : {projects_id}"
== map_family_data_output[1]
)
6 changes: 3 additions & 3 deletions tests/unit_tests/parsers/family/test_map_family_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_dates_contain_invalid_date_entries(list_of_dates: list, return_value):
"DateCompletion": pd.NA,
}
),
"🛑 Row contains invalid date entries",
"- Row contains invalid date entries",
),
(
pd.Series(
Expand All @@ -256,7 +256,7 @@ def test_dates_contain_invalid_date_entries(list_of_dates: list, return_value):
"DateCompletion": "",
}
),
"🛑 Row contains invalid date entries",
"- Row contains invalid date entries",
),
(
pd.Series(
Expand All @@ -266,7 +266,7 @@ def test_dates_contain_invalid_date_entries(list_of_dates: list, return_value):
"DateCompletion": None,
}
),
"🛑 Row missing event date information to calculate status",
"- Row missing event date information to calculate status",
),
],
)
Expand Down

0 comments on commit c65278c

Please sign in to comment.