Compare commits

...

2 commits

Author SHA1 Message Date
Edward Betts 4863eb59d5 Improve tests
Closes: #1
2024-06-19 14:00:28 +01:00
Edward Betts a04106ce1f Bug fix format_wikibase_time centuries 2024-06-19 13:59:52 +01:00
2 changed files with 16 additions and 3 deletions

View file

@ -204,7 +204,7 @@ def format_wikibase_time(v: WikibaseTime) -> str | None:
case 7: # century case 7: # century
century = ((int(t[:5]) - 1) // 100) + 1 century = ((int(t[:5]) - 1) // 100) + 1
ordinal_num = num2words(abs(century), to="ordinal_num") ordinal_num = num2words(abs(century), to="ordinal_num")
return f"{ordinal_num} {century}{' BC' if century < 0 else ''}" return f"{ordinal_num} century{' BC' if century < 0 else ''}"
case 6: # millennium case 6: # millennium
millennium = ((int(t[:5]) - 1) // 1000) + 1 millennium = ((int(t[:5]) - 1) // 1000) + 1
ordinal_num = num2words(abs(millennium), to="ordinal_num") ordinal_num = num2words(abs(millennium), to="ordinal_num")

View file

@ -1,17 +1,30 @@
"""Test matcher utils."""
from matcher import utils from matcher import utils
def test_format_wikibase_time_year(): def test_format_wikibase_time_year() -> None:
"""Test passing a year to format_wikibase_time."""
v = {"time": "+1950-00-00T00:00:00Z", "precision": 9} v = {"time": "+1950-00-00T00:00:00Z", "precision": 9}
assert utils.format_wikibase_time(v) == "1950" assert utils.format_wikibase_time(v) == "1950"
def test_format_wikibase_time_century(): def test_format_wikibase_time_century() -> None:
"""Test passing centuries to format_wikibase_time."""
v = {"time": "+0800-00-00T00:00:00Z", "precision": 7} v = {"time": "+0800-00-00T00:00:00Z", "precision": 7}
assert utils.format_wikibase_time(v) == "8th century" assert utils.format_wikibase_time(v) == "8th century"
v = {"time": "+1950-00-00T00:00:00Z", "precision": 7} v = {"time": "+1950-00-00T00:00:00Z", "precision": 7}
assert utils.format_wikibase_time(v) == "20th century" assert utils.format_wikibase_time(v) == "20th century"
def test_format_wikibase_time_decade() -> None:
"""Test passing a full date to format_wikibase_time."""
v = {"time": "+1910-00-00T00:00:00Z", "precision": 8}
assert utils.format_wikibase_time(v) == "1910s"
def test_format_wikibase_time_day() -> None:
"""Test passing a full date to format_wikibase_time."""
v = {"time": "+1868-01-09T00:00:00Z", "precision": 11} v = {"time": "+1868-01-09T00:00:00Z", "precision": 11}
assert utils.format_wikibase_time(v) == "9 January 1868" assert utils.format_wikibase_time(v) == "9 January 1868"