Skip to content

Commit

Permalink
Improve test coverage and error handling for EDTF
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Nov 8, 2024
1 parent 3531bb9 commit b821923
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/undate/converters/edtf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ def _undate_to_string(self, undate: Undate) -> str:
return "-".join(parts)

# how can we have an empty string? probably shouldn't get here
return ""
raise ValueError("Failed to generate an EDTF string from %r", undate)
8 changes: 8 additions & 0 deletions tests/test_converters/test_edtf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from undate.converters.edtf import EDTFDateConverter
from undate.date import DatePrecision
from undate.undate import Undate, UndateInterval


Expand Down Expand Up @@ -52,5 +53,12 @@ def test_to_string(self):

assert EDTFDateConverter().to_string(Undate(1991, "0X")) == "1991-0X"
assert EDTFDateConverter().to_string(Undate(1991, None, 3)) == "1991-XX-03"
assert EDTFDateConverter().to_string(Undate(-1984)) == "-1984"

# if converter can't generate a string for the date,
# it should return a value error
empty_undate = Undate()
empty_undate.precision = DatePrecision.DECADE
with pytest.raises(ValueError):
EDTFDateConverter().to_string(empty_undate)
# TODO: override missing digit and confirm replacement

0 comments on commit b821923

Please sign in to comment.