_preprocess now sets approx=True when a leading marker is stripped; add _match_year_only so bare years (e.g. "nach 1900" -> "1900") resolve to 1900-01-01/YEAR before being upgraded to APPROX. Strengthen test_parse_approx_marker_upgrades_precision and add test_parse_leading_qualifier_is_approx (11 tests, all pass). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
66 lines
3.2 KiB
Python
66 lines
3.2 KiB
Python
import datetime
|
|
import dates
|
|
from dates import Precision
|
|
|
|
def test_easter_known_years():
|
|
# Anonymous Gregorian algorithm — verified against published tables
|
|
assert dates.easter(2024) == datetime.date(2024, 3, 31)
|
|
assert dates.easter(2000) == datetime.date(2000, 4, 23)
|
|
assert dates.easter(1922) == datetime.date(1922, 4, 16)
|
|
assert dates.easter(1888) == datetime.date(1888, 4, 1)
|
|
|
|
def test_resolve_feast_movable():
|
|
assert dates.resolve_feast_or_season("Pfingsten", 1922) == ("1922-06-04", Precision.DAY)
|
|
assert dates.resolve_feast_or_season("Ostern", 2024) == ("2024-03-31", Precision.DAY)
|
|
assert dates.resolve_feast_or_season("Pfingstmontag", 1922) == ("1922-06-05", Precision.DAY)
|
|
|
|
def test_resolve_feast_fixed():
|
|
assert dates.resolve_feast_or_season("Weihnachten", 1900) == ("1900-12-25", Precision.DAY)
|
|
assert dates.resolve_feast_or_season("Neujahr", 1910) == ("1910-01-01", Precision.DAY)
|
|
|
|
def test_resolve_season():
|
|
assert dates.resolve_feast_or_season("Herbst", 1913) == ("1913-10-01", Precision.SEASON)
|
|
assert dates.resolve_feast_or_season("Sommer", 1910) == ("1910-07-01", Precision.SEASON)
|
|
|
|
def test_resolve_unknown_token_returns_none():
|
|
assert dates.resolve_feast_or_season("Freitag", 1919) is None
|
|
|
|
def test_expand_year():
|
|
assert dates.expand_year("1888") == 1888
|
|
assert dates.expand_year("889") == 1889 # 3-digit -> 1DDD
|
|
assert dates.expand_year("923") == 1923
|
|
assert dates.expand_year("08") == 1908 # 00..57 -> 19xx
|
|
assert dates.expand_year("17") == 1917
|
|
assert dates.expand_year("57") == 1957
|
|
assert dates.expand_year("73") == 1873 # 73..99 -> 18xx
|
|
assert dates.expand_year("99") == 1899
|
|
assert dates.expand_year("65") is None # 58..72 ambiguous
|
|
assert dates.expand_year("x") is None
|
|
|
|
def test_parse_iso_and_empty():
|
|
assert dates.parse_date("1910-04-23") == dates.ParsedDate("1910-04-23", Precision.DAY, "1910-04-23")
|
|
assert dates.parse_date("") == dates.ParsedDate(None, Precision.UNKNOWN, "")
|
|
assert dates.parse_date("?") == dates.ParsedDate(None, Precision.UNKNOWN, "?")
|
|
|
|
def test_parse_numeric_forms():
|
|
assert dates.parse_date("15.2.1888").iso == "1888-02-15"
|
|
assert dates.parse_date("13.5.09").iso == "1909-05-13"
|
|
assert dates.parse_date("17/6. 1916").iso == "1916-06-17"
|
|
assert dates.parse_date("11.10.08").iso == "1908-10-11"
|
|
assert dates.parse_date("30.1.889").iso == "1889-01-30"
|
|
assert dates.parse_date("15.2.1888").precision == Precision.DAY
|
|
|
|
def test_parse_numeric_unparseable():
|
|
assert dates.parse_date("8.9.").precision == Precision.UNKNOWN # no year
|
|
assert dates.parse_date("13.5.65").precision == Precision.UNKNOWN # ambiguous 2-digit year
|
|
|
|
def test_parse_approx_marker_upgrades_precision():
|
|
r = dates.parse_date("17.Nov (?) 1887") # month-name handled in a later task; here just the marker path
|
|
assert r.raw == "17.Nov (?) 1887"
|
|
assert r.precision == Precision.UNKNOWN # no month-name matcher until Task 7; full APPROX check in Task 8
|
|
|
|
def test_parse_leading_qualifier_is_approx():
|
|
r = dates.parse_date("nach 1900") # "after 1900" -> year salvaged, but precision is APPROX not exact
|
|
assert r.iso == "1900-01-01"
|
|
assert r.precision == Precision.APPROX
|