from datetime import date, datetime from app.api.pl.public_transport import ( _history_matches_date, _normalize_main_plate, _parse_history_date, _history_status_label, ) def test_normalize_main_plate_trims(): assert _normalize_main_plate(" 苏AD12345 ") == "苏AD12345" assert _normalize_main_plate(None) == "" assert _normalize_main_plate("") == "" def test_parse_history_date_ok_and_bad(): assert _parse_history_date("2026-08-21") == date(2026, 8, 21) assert _parse_history_date("2026/08/21") is None assert _parse_history_date("") is None def test_history_matches_date_or_logic(): day = date(2026, 8, 21) assert _history_matches_date(datetime(2026, 8, 21, 9, 0), None, day) is True assert _history_matches_date(None, datetime(2026, 8, 21, 18, 0), day) is True assert _history_matches_date( datetime(2026, 8, 20, 9, 0), datetime(2026, 8, 22, 18, 0), day ) is False assert _history_matches_date(None, None, day) is False def test_history_status_label(): assert _history_status_label(True, False) == "已作废" assert _history_status_label(True, True) == "已作废" assert _history_status_label(False, True) == "已归档" assert _history_status_label(False, False) == "进行中"