Skip to content

Commit

Permalink
fix: handle unexpected release date (#262)
Browse files Browse the repository at this point in the history
* handle unexpected release date
* add test case for 0000-00-00 in release date

More cases to follow once we either decide to keep single year records or other refactoring is ready

---------

Co-authored-by: spameier <[email protected]>
Co-authored-by: Lucas <[email protected]>
  • Loading branch information
3 people authored May 16, 2023
1 parent 0285d9b commit 55bf145
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion suisa_sendemeldung/suisa_sendemeldung.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,10 @@ def funge_release_date(release_date: str = ""):

if len(release_date) == 10:
# we can make it look like what suisa has in their examples if it's the right length
return datetime.strptime(release_date, "%Y-%m-%d").strftime("%Y%m%d")
try:
return datetime.strptime(release_date, "%Y-%m-%d").strftime("%Y%m%d")
except ValueError:
return ""
# we discard other records since there is no way to convert records like a plain
# year into dd/mm/yyyy properly without further guidance from whomever ingests
# the data, in some cases this means we discard data that only contain a year
Expand Down
13 changes: 13 additions & 0 deletions tests/test_suisa_sendemeldung.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,19 @@ def test_merge_duplicates():
assert results[0]["metadata"]["played_duration"] == 20


@mark.parametrize(
"test_date,expected",
[
("0000-00-00", ""),
],
)
def test_funge_release_date(test_date, expected):
"""Test funge_release_date."""

results = suisa_sendemeldung.funge_release_date(test_date)
assert results == expected


@patch("cridlib.get")
def test_get_csv(mock_cridlib_get):
"""Test get_csv."""
Expand Down

0 comments on commit 55bf145

Please sign in to comment.