fix: raise ParseError for out-of-range times
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
8099b4834b
commit
ba35014a06
2 files changed
+23
-1
No files matched your search
@@ -103,3 +103,21 @@ def test_cell_count_mismatch_is_a_parse_error():
|
||||
)
|
||||
with pytest.raises(ParseError, match="cells"):
|
||||
parse_page(html, "4", "X")
|
||||
|
||||
|
||||
def test_invalid_hour_is_a_parse_error():
|
||||
html = HEADER.format(
|
||||
ths=WORKDAY_TH,
|
||||
rows='<tr><td class="hour-cell">25</td><td class="minutes-cell">10 </td></tr>',
|
||||
)
|
||||
with pytest.raises(ParseError, match="invalid time"):
|
||||
parse_page(html, "4", "X")
|
||||
|
||||
|
||||
def test_invalid_minute_is_a_parse_error():
|
||||
html = HEADER.format(
|
||||
ths=WORKDAY_TH,
|
||||
rows='<tr><td class="hour-cell">04</td><td class="minutes-cell">99 </td></tr>',
|
||||
)
|
||||
with pytest.raises(ParseError, match="invalid time"):
|
||||
parse_page(html, "4", "X")
|
||||
+5
-1
@@ -93,7 +93,11 @@ def parse_page(html: str, line: str, stop: str) -> Timetable:
|
||||
raise ParseError(f"hour {hour}: {len(cells)} cells for {len(specs)} columns")
|
||||
for column, cell in zip(per_column, cells):
|
||||
for minute, mark in _MINUTE_RE.findall(cell):
|
||||
column.append(Departure(line, stop, time(int(hour), int(minute)), mark or None))
|
||||
try:
|
||||
departure_time = time(int(hour), int(minute))
|
||||
except ValueError:
|
||||
raise ParseError(f"hour {hour}: invalid time {hour}:{minute}")
|
||||
column.append(Departure(line, stop, departure_time, mark or None))
|
||||
|
||||
if not any(per_column):
|
||||
raise ParseError("timetable contains no departures")
|
||||
|
||||
Reference in new issue
Block a user