def test_self_generate(self): parsed_subs1 = utils.get_subs("simple.dfxp") parsed_subs2 = DFXPParser( DFXPGenerator(parsed_subs1.subtitle_set, 'en').__unicode__()) for x1, x2 in zip([x for x in parsed_subs1.to_internal()], [x for x in parsed_subs2.to_internal()]): self.assertEquals(x1, x2)
def test_unsynced_generator(self): subs = SubtitleSet('en') for x in xrange(0,5): subs.append_subtitle(None, None,"%s" % x) output = unicode(DFXPGenerator(subs)) parsed = DFXPParser(output, 'en') internal = parsed.to_internal() subs = [x for x in internal.subtitle_items()] self.assertEqual(len(internal), 5) for i,sub in enumerate(subs): self.assertIsNone(sub[0]) self.assertIsNone(sub[1]) self.assertEqual(sub[2], str(i)) for node in internal.get_subtitles(): self.assertIsNone(get_attr(node, 'begin')) self.assertIsNone(get_attr(node, 'end'))
def test_dfxp_serializer(self): video = get_video() sl_en = make_subtitle_language(video, 'en') video.primary_audio_language_code = 'en' video.save() make_subtitle_version(sl_en, [(100, 200, 'Here we go!')], title='title') content = self._download_subs(sl_en, 'dfxp') serialized = DFXPParser(content) subtitle_set = serialized.to_internal() self.assertEqual(len(subtitle_set), 1) start, end, content, meta = list(subtitle_set)[0] self.assertEqual(start, 100) self.assertEqual(end, 200) self.assertEqual(content, 'Here we go!')
def test_dfxp_serializer(self): video = get_video() sl_en = make_subtitle_language(video, 'en') video.primary_audio_language_code = 'en' video.save() self.test_title = "This is a really long title used to make sure we are not truncating file names" self.assertTrue(len(self.test_title) > 60) make_subtitle_version( sl_en, [(100, 200, 'Here we go!')], title=self.test_title, ) content = self._download_subs(sl_en, 'dfxp') serialized = DFXPParser(content) subtitle_set = serialized.to_internal() self.assertEqual(len(subtitle_set), 1) start, end, content, meta = list(subtitle_set)[0] self.assertEqual(start, 100) self.assertEqual(end, 200) self.assertEqual(content, 'Here we go!')
def test_wrong_format(self): with self.assertRaises(SubtitleParserError): DFXPParser.parse(SRT_TEXT)
def test_self_generate(self): parsed_subs1 = utils.get_subs("simple.dfxp") parsed_subs2 = DFXPParser(DFXPGenerator(parsed_subs1.subtitle_set, 'en').__unicode__()) for x1, x2 in zip([x for x in parsed_subs1.to_internal()], [x for x in parsed_subs2.to_internal()]): self.assertEquals(x1, x2)
def test_invalid(self): with self.assertRaises(SubtitleParserError): DFXPParser ("this\n\nisnot a valid subs format","en")