class TestSRTWriter(unittest.TestCase): def setUp(self): test_content = StringIO(u"""WEBVTT - it does not matter what is here 1 00:03.490 --> 00:00:07.430 FISHER: All right. So, let's begin. This session is: Going Šocial 00:07.430 --> 00:00:11.600 with the YouTube APIs. I am Jeff Fisher, idsarenotnecessarilynumbers 00:00:11.600 --> 00:00:14.009 and this is Johann Hartmann, we're presenting today. 3 00:00:14.009 --> 00:00:15.889 position:10%,start align:start region:nobodycares size:35% [pause] """) self.reader = Reader(test_content) self.writer = Writer(StringIO()) def test_transformtext(self): captions = self.reader.read() self.writer.captions = captions text = self.writer.captions_to_text() should_be = u"""WEBVTT\n\n0\n00:00:03.490 --> 00:00:07.430\nFISHER: All right. So, let's begin.\nThis session is: Going Šocial""" self.assertTrue(text.startswith(should_be), "%s !startswith %s" % (text, should_be)) def test_format_time(self): caption = core.Caption() caption.start = core.get_date(second=3, millisecond=490) caption.end = core.get_date(second=7, millisecond=430) time_info = self.writer.format_time(caption) self.assertEqual(time_info['start'], '00:00:03.490') self.assertEqual(time_info['end'], '00:00:07.430')
def setUp(self): test_content = StringIO(u"""WEBVTT - it does not matter what is here 1 00:03.490 --> 00:00:07.430 FISHER: All right. So, let's begin. This session is: Going Šocial 00:07.430 --> 00:00:11.600 with the YouTube APIs. I am Jeff Fisher, idsarenotnecessarilynumbers 00:00:11.600 --> 00:00:14.009 and this is Johann Hartmann, we're presenting today. 3 00:00:14.009 --> 00:00:15.889 position:10%,start align:start region:nobodycares size:35% [pause] """) self.reader = Reader(test_content) self.writer = Writer(StringIO())