48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
from datetime import date
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
from rf4_research.records import RecordsParseError, parse_records_html, parse_weight_g
|
|
|
|
|
|
FIXTURE = Path(__file__).parent / "fixtures" / "records_ru_sample.html"
|
|
|
|
|
|
class RecordsParserTests(unittest.TestCase):
|
|
def test_parses_group_header_and_nested_records(self) -> None:
|
|
records = parse_records_html(
|
|
FIXTURE.read_text(encoding="utf-8"),
|
|
region="ru",
|
|
category="records",
|
|
source_url="https://rf4game.de/records/region/RU/",
|
|
today=date(2026, 9, 2),
|
|
)
|
|
|
|
self.assertEqual(len(records), 2)
|
|
self.assertEqual(records[0].fish, "Hecht")
|
|
self.assertEqual(records[0].weight_g, 27_902)
|
|
self.assertEqual(records[0].bait, "Testköder 01")
|
|
self.assertEqual(records[1].fish, "Hecht")
|
|
self.assertEqual(records[1].weight_g, 2_519_264)
|
|
self.assertEqual(records[1].record_date, date(2026, 5, 3))
|
|
|
|
def test_rejects_changed_column_contract(self) -> None:
|
|
html = FIXTURE.read_text(encoding="utf-8").replace(
|
|
'class="col data"', 'class="col changed"', 1
|
|
)
|
|
with self.assertRaisesRegex(RecordsParseError, "records columns changed"):
|
|
parse_records_html(
|
|
html,
|
|
region="RU",
|
|
category="records",
|
|
source_url="fixture://changed",
|
|
)
|
|
|
|
def test_weight_units_are_normalized_to_grams(self) -> None:
|
|
self.assertEqual(parse_weight_g("423 g"), 423)
|
|
self.assertEqual(parse_weight_g("8.023 kg"), 8_023)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|