Преглед на файлове

test(movie): verify first subtitle cue offset

Drew Ritter преди 3 седмици
родител
ревизия
2996ad255c
променени са 2 файла, в които са добавени 20 реда и са изтрити 4 реда
  1. 5 1
      tests/proving-it-works-with-a-movie/README.md
  2. 15 3
      tests/proving-it-works-with-a-movie/test_assembly.py

+ 5 - 1
tests/proving-it-works-with-a-movie/README.md

@@ -25,7 +25,7 @@ inputs exercise text comparison only. Neither is speech/ASR acceptance.
 | `test-assemble.sh` | `assemble runs` | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-assemble.sh` | `assemble runs` | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-assemble.sh` | `segment = max(narration, visuals)` (8s +/- 0.4s) | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-assemble.sh` | `segment = max(narration, visuals)` (8s +/- 0.4s) | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-assemble.sh` | `offsets.json places the narrated scene` (2s +/- 0.3s) | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-assemble.sh` | `offsets.json places the narrated scene` (2s +/- 0.3s) | `AssemblyRegression.test_narration_padding_and_offsets` |
-| `test-assemble.sh` | `cues start at the scene's real offset, not zero` | `AssemblyRegression.test_narration_padding_and_offsets` |
+| `test-assemble.sh` | `cues start at the scene's real offset, not zero` (first cue start equals the measured body offset within 1ms) | `AssemblyRegression.test_narration_padding_and_offsets` |
 | `test-check-movie.sh` | `front-loaded action is rejected` | `CheckerRegression.test_front_loaded_action_is_rejected` |
 | `test-check-movie.sh` | `front-loaded action is rejected` | `CheckerRegression.test_front_loaded_action_is_rejected` |
 | `test-check-movie.sh` | `paced + subtitles is accepted` | `CheckerRegression.test_paced_with_subtitles_is_accepted` |
 | `test-check-movie.sh` | `paced + subtitles is accepted` | `CheckerRegression.test_paced_with_subtitles_is_accepted` |
 | `test-check-movie.sh` | `narrated without subtitles rejected` | `CheckerRegression.test_narrated_without_subtitles_is_rejected` |
 | `test-check-movie.sh` | `narrated without subtitles rejected` | `CheckerRegression.test_narrated_without_subtitles_is_rejected` |
@@ -40,3 +40,7 @@ inputs exercise text comparison only. Neither is speech/ASR acceptance.
 | `test-narrate.sh` | `a dropped clause fails` | `NarrationDriftRegression.test_dropped_clause_fails` |
 | `test-narrate.sh` | `a dropped clause fails` | `NarrationDriftRegression.test_dropped_clause_fails` |
 | `test-narrate.sh` | `an invented preamble fails` | `NarrationDriftRegression.test_invented_preamble_fails` |
 | `test-narrate.sh` | `an invented preamble fails` | `NarrationDriftRegression.test_invented_preamble_fails` |
 | `test-narrate.sh` | `an empty clip fails` | `NarrationDriftRegression.test_empty_clip_fails` |
 | `test-narrate.sh` | `an empty clip fails` | `NarrationDriftRegression.test_empty_clip_fails` |
+
+The portable subtitle assertion intentionally strengthens the Bash suite's
+whole-file regex: it parses the first cue start and compares it with the actual
+assembly offset at SRT's millisecond precision.

+ 15 - 3
tests/proving-it-works-with-a-movie/test_assembly.py

@@ -40,9 +40,21 @@ class AssemblyRegression(unittest.TestCase):
             self.assertEqual(
             self.assertEqual(
                 subtitles.returncode, 0, fixtures.output_text(subtitles)
                 subtitles.returncode, 0, fixtures.output_text(subtitles)
             )
             )
-            self.assertRegex(
-                (work / "out.srt").read_text(encoding="utf-8"),
-                r"00:00:0[2-9]",
+            srt = (work / "out.srt").read_text(encoding="utf-8")
+            timing_line = next(line for line in srt.splitlines() if "-->" in line)
+            start = timing_line.partition("-->")[0].strip()
+            hours, minutes, seconds_millis = start.split(":")
+            seconds, millis = seconds_millis.split(",")
+            first_cue_start = (
+                int(hours) * 3600
+                + int(minutes) * 60
+                + int(seconds)
+                + int(millis) / 1000
+            )
+            self.assertAlmostEqual(
+                first_cue_start,
+                offsets["body"],
+                delta=0.001,
             )
             )