Skip to content

Commit

Permalink
Fixes tests AE-45
Browse files Browse the repository at this point in the history
  • Loading branch information
dsavinov-actionengine committed Jul 5, 2024
1 parent 842846b commit ed01449
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions openformats/formats/vtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def parse(self, content, **kwargs):
self.transcriber.copy_until(len(source))

template = self.transcriber.get_destination()
if len(stringset) == 0:
raise ParseError("There are no strings to translate")
elif not template.startswith("WEBVTT"):
if not template.startswith("WEBVTT"):
raise ParseError("VTT file should start with 'WEBVTT'!")
return template, stringset

Expand Down Expand Up @@ -103,6 +101,9 @@ def _parse_section(self, offset, section):

# Content
string_to_translate = "\n".join(src_strings[timings_index + 1 :])
if string_to_translate == "":
# Do not include an empty subtitle in the stringset
return None, None

string = OpenString(
timings,
Expand Down
7 changes: 3 additions & 4 deletions openformats/tests/formats/vtt/test_vtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ def test_vtt_occurrences(self):
_, stringset = self.handler.parse(source)
self.assertEqual(stringset[0].occurrences, '00:01:28.797,00:01:30.297')

def test_empty_subtitle(self):
def test_missing_string(self):
source = strip_leading_spaces("""WEBVTT
1
00:01:28.797 --> 00:01:30.297
""")
template, stringset = self.handler.parse(source)
self.assertIn('WEBVTT', template)
self.assertEqual(len(stringset), 1)
template, _ = self.handler.parse(source)
self.assertEqual(source, template)

def test_full_and_short_timings(self):
source = strip_leading_spaces("""WEBVTT
Expand Down

0 comments on commit ed01449

Please sign in to comment.