Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date-ranges-test-fixes #3307

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ def parse_date_into_range(
errors=[],
)

logger.debug(f"release_date: {release_date}")

formats_to_messages = {
"%Y-%m-%d": None,
"%Y-%m": "Day is missing. Assuming date is some time in the month.",
Expand Down Expand Up @@ -277,12 +275,6 @@ class DateRange:
date_range_lower=parsed_date.replace(month=1, day=1),
date_range_upper=parsed_date.replace(month=12, day=31),
)
case "_":
datum = DateRange(
date_range_string=None,
date_range_lower=None,
date_range_upper=max_upper_limit,
)

logger.debug(f"parsed_date: {datum}")

Expand Down
88 changes: 67 additions & 21 deletions preprocessing/nextclade/tests/test_processing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,27 +483,73 @@ def test_format_authors() -> None:
raise AssertionError(msg)


def test_parse_date_into_range():
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeString"}
), "2021-12"
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeLower"}
), "2021-12-01"
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeUpper"}
), "2021-12-31"
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021-02"}, "field_name", {"fieldType": "dateRangeUpper"}
), "2021-02-28"
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021"}, "field_name", {"fieldType": "dateRangeUpper"}
), "2021-12-31"
assert ProcessingFunctions.parse_date_into_range(
{"date": "2021-12", "releaseDate": "2021-12-15"},
"field_name",
{"fieldType": "dateRangeUpper"},
), "2021-12-15"
def test_parse_date_into_range() -> None:
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeString"}
).datum
== "2021-12"
), "dateRangeString: 2021-12 should be returned as is."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeLower"}
).datum
== "2021-12-01"
), "dateRangeLower: 2021-12 should be returned as 2021-12-01."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021-12"}, "field_name", {"fieldType": "dateRangeUpper"}
).datum
== "2021-12-31"
), "dateRangeUpper: 2021-12 should be returned as 2021-12-31."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021-02"}, "field_name", {"fieldType": "dateRangeUpper"}
).datum
== "2021-02-28"
), "dateRangeUpper: 2021-02 should be returned as 2021-02-28."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021"}, "field_name", {"fieldType": "dateRangeUpper"}
).datum
== "2021-12-31"
), "dateRangeUpper: 2021 should be returned as 2021-12-31."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "2021-12", "releaseDate": "2021-12-15"},
"field_name",
{"fieldType": "dateRangeUpper"},
).datum
== "2021-12-15"
), "dateRangeUpper: 2021-12 with releaseDate 2021-12-15 should be returned as 2021-12-15."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "", "releaseDate": "2021-12-15"},
"field_name",
{"fieldType": "dateRangeUpper"},
).datum
== "2021-12-15"
), "dateRangeUpper: empty date with releaseDate 2021-12-15 should be returned as 2021-12-15."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": ""}, "field_name", {"fieldType": "dateRangeString"}
).datum
is None
), "dateRangeString: empty date should be returned as None."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "not.date"}, "field_name", {"fieldType": "dateRangeString"}
).datum
is None
), "dateRangeString: invalid date should be returned as None."
assert (
ProcessingFunctions.parse_date_into_range(
{"date": "", "releaseDate": "2021-12-15"},
"field_name",
{"fieldType": "dateRangeLower"},
).datum
is None
), "dateRangeLower: empty date should be returned as None."


if __name__ == "__main__":
Expand Down