Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pycaption/sami/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ def _translate_lang(self, language, sami_soup, parent_layout):
raise CaptionReadTimingError(
f"Missing start time on the following line: {p.parent}."
)
milliseconds = int(float(start_str))
try:
milliseconds = int(float(start_str))
except ValueError:
raise CaptionReadTimingError(
f"Invalid start time on the following line: {p.parent}."
)
start = milliseconds * 1000

self._backfill_end_times(captions, start)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_sami.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def test_missing_start(self, sample_sami_missing_start):
"Missing start time on the following line: "
)

def test_non_numeric_start(self):
# A non-numeric SYNC start attribute used to raise a bare ValueError
# from int(float(start_str)); it should be a CaptionReadTimingError.
content = "<SAMI><BODY><SYNC Start=abc><P>Hi</P></SYNC></BODY></SAMI>"
with pytest.raises(CaptionReadTimingError) as exc_info:
self.reader.read(content)

assert exc_info.value.args[0].startswith(
"Invalid start time on the following line: "
)

def test_6digit_color_code_from_6digit_input(self, sample_sami):
caption_set = self.reader.read(sample_sami)
p_style = caption_set.get_style("p")
Expand Down