2024-06-19 14:00:28 +01:00
|
|
|
"""Test matcher utils."""
|
2024-08-28 10:54:05 +01:00
|
|
|
from unittest import TestCase
|
2024-06-19 14:00:28 +01:00
|
|
|
|
2021-11-13 16:27:46 +00:00
|
|
|
from matcher import utils
|
|
|
|
|
|
|
|
|
2024-08-28 10:54:05 +01:00
|
|
|
class TestUtils(TestCase):
|
|
|
|
def test_format_wikibase_time_year(self) -> None:
|
|
|
|
"""Test passing a year to format_wikibase_time."""
|
|
|
|
v = {"time": "+1950-00-00T00:00:00Z", "precision": 9}
|
|
|
|
assert utils.format_wikibase_time(v) == "1950"
|
2021-11-13 16:27:46 +00:00
|
|
|
|
2024-08-28 10:54:05 +01:00
|
|
|
def test_format_wikibase_time_century(self) -> None:
|
|
|
|
"""Test passing centuries to format_wikibase_time."""
|
|
|
|
v = {"time": "+0800-00-00T00:00:00Z", "precision": 7}
|
|
|
|
assert utils.format_wikibase_time(v) == "8th century"
|
2021-11-14 08:01:19 +00:00
|
|
|
|
2024-08-28 10:54:05 +01:00
|
|
|
v = {"time": "+1950-00-00T00:00:00Z", "precision": 7}
|
|
|
|
assert utils.format_wikibase_time(v) == "20th century"
|
2021-11-13 16:27:46 +00:00
|
|
|
|
2024-08-28 10:54:05 +01:00
|
|
|
def test_format_wikibase_time_decade(self) -> 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"
|
2022-04-08 10:35:21 +01:00
|
|
|
|
2024-08-28 10:54:05 +01:00
|
|
|
def test_format_wikibase_time_day(self) -> None:
|
|
|
|
"""Test passing a full date to format_wikibase_time."""
|
|
|
|
v = {"time": "+1868-01-09T00:00:00Z", "precision": 11}
|
|
|
|
assert utils.format_wikibase_time(v) == "9 January 1868"
|