def test_escaping_list(self): subtitles = ((0, 1000, "Hey <a>html anchor</a>", ),) dfxp = storage.SubtitleSet.from_list('en', subtitles) self.assertEqual( storage.get_contents(dfxp.get_subtitles()[0]), 'Hey html anchor') dfxp = storage.SubtitleSet.from_list('en', subtitles, escape=True) self.assertEqual( storage.get_contents(dfxp.get_subtitles()[0]), 'Hey <a>html anchor</a>')
def test_escaping(self): dfxp = storage.SubtitleSet('en') dfxp.append_subtitle(0, 1000, "Hey <a>html anchor</a>", escape=False) dfxp.append_subtitle(0, 1000, "Hey <a>html anchor</a>", escape=True) self.assertEqual(storage.get_contents(dfxp.get_subtitles()[0]), 'Hey html anchor') self.assertEqual(storage.get_contents(dfxp.get_subtitles()[1]), 'Hey <a>html anchor</a>')
def test_speaker_change(self): subs = """1 00:00:00,004 --> 00:00:02,093 And know, Mr. <b>Amara</b> will talk.\n >> Hello, and welcome. """ parsed = SRTParser(subs, 'en') internal = parsed.to_internal() self.assertEquals(len(parsed), 1) element = internal.get_subtitles()[0] self.assertTrue(len(element.getchildren()), 2) self.assertEquals( get_contents(element), 'And know, Mr. Amara will talk. >> Hello, and welcome.') self.assertEquals( etree.tostring(element), '<p xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" begin="00:00:00.004" end="00:00:02.093">And know, Mr. <span tts:fontWeight="bold">Amara</span> will talk.<br/> >> Hello, and welcome.</p>' ) self.assertEquals(element.getchildren()[1].tail, ' >> Hello, and welcome.') output = unicode(SRTGenerator(internal)) parsed2 = SRTParser(output, 'en') internal2 = parsed2.to_internal() for x1, x2 in zip([x for x in internal.subtitle_items(SRTGenerator.MAPPINGS)], \ [x for x in internal2.subtitle_items(SRTGenerator.MAPPINGS)]): self.assertEquals(x1, x2)
def test_speaker_change(self): subs = """1 00:00:00,004 --> 00:00:02,093 And know, Mr. <b>Amara</b> will talk.\n >> Hello, and welcome. """ parsed = SRTParser(subs, 'en') internal = parsed.to_internal() self.assertEquals(len(parsed), 1) element = internal.get_subtitles()[0] self.assertTrue(len(element.getchildren()), 2) self.assertEquals(get_contents(element), 'And know, Mr. Amara will talk. >> Hello, and welcome.') self.assertEquals(etree.tostring(element).strip(), '<p xmlns="http://www.w3.org/ns/ttml" xmlns:tts="http://www.w3.org/ns/ttml#styling" begin="00:00:00.004" end="00:00:02.093">And know, Mr. <span tts:fontWeight="bold">Amara</span> will talk.<br/> >> Hello, and welcome.</p>') self.assertEquals(element.getchildren()[1].tail, ' >> Hello, and welcome.') output = unicode(SRTGenerator(internal)) parsed2 = SRTParser(output, 'en') internal2 = parsed2.to_internal() for x1, x2 in zip([x for x in internal.subtitle_items(SRTGenerator.MAPPINGS)], \ [x for x in internal2.subtitle_items(SRTGenerator.MAPPINGS)]): self.assertEquals(x1, x2)
def test_nested_tags(self): dfxp = utils.get_subs("simple.dfxp").to_internal() self.assertEqual( storage.get_contents(dfxp.get_subtitles()[37]), 'nested spans') self.assertEqual( storage.get_contents(dfxp.get_subtitles()[38]), 'a word on nested spans')
def test_escaping(self): dfxp = storage.SubtitleSet('en') dfxp.append_subtitle(0, 1000, "Hey <a>html anchor</a>", escape=False) dfxp.append_subtitle(0, 1000, "Hey <a>html anchor</a>", escape=True) self.assertEqual( storage.get_contents(dfxp.get_subtitles()[0]), 'Hey html anchor') self.assertEqual( storage.get_contents(dfxp.get_subtitles()[1]), 'Hey <a>html anchor</a>')
def test_nested_tags(self): dfxp = utils.get_subs("simple.dfxp").to_internal() self.assertEqual(storage.get_contents(dfxp.get_subtitles()[37]), 'nested spans') self.assertEqual(storage.get_contents(dfxp.get_subtitles()[38]), 'a word on nested spans')