import os import unittest from hpr_stripper import srt REFERENCES_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "references") class TestSrtParsing(unittest.TestCase): def test_parses_vendored_outro_srt(self): segments = srt.parse_file(os.path.join(REFERENCES_DIR, "outro.srt")) self.assertEqual(len(segments), 5) text0, start0, end0 = segments[0] self.assertIn("Hacker Public Radio podcast", text0) self.assertEqual(start0, 0.0) self.assertAlmostEqual(end0, 5.56, places=2) def test_parses_vendored_intro_srt_template(self): segments = srt.parse_file(os.path.join(REFERENCES_DIR, "intro.srt")) self.assertEqual(len(segments), 5) self.assertEqual(segments[0][0], "REPLACE_LINE_1") self.assertAlmostEqual(segments[-1][2], 27.32, places=2) def test_handles_comma_or_dot_decimal_separator(self): text = ( "1\n00:00:01,000 --> 00:00:02,500\nHello there\n\n" "2\n00:00:02.500 --> 00:00:04.000\nSecond line\n" ) segments = srt.parse(text) self.assertEqual(len(segments), 2) self.assertEqual(segments[0], ("Hello there", 1.0, 2.5)) self.assertEqual(segments[1], ("Second line", 2.5, 4.0)) if __name__ == "__main__": unittest.main()