def test_timed_data_parses_correctly(self): subs = utils.get_data_file_path('timed_text.srt') parsed = babelsubs.load_from_file(subs, type='srt', language='en') self.assertNotEquals(parsed, None) try: srt = parsed.to('srt') self.assertNotEquals(srt, None) except Exception, e: self.fail(e)
def test_normalize_time(self): content_str = open(utils.get_data_file_path("normalize-time.dfxp") ).read() dfxp = storage.SubtitleSet('en', content_str, normalize_time=True) subs = dfxp.get_subtitles() self.assertTrue(len(dfxp) ) for el in subs: self.assertIn("begin", el.attrib) self.assertTrue(storage.TIME_EXPRESSION_CLOCK_TIME.match(el.attrib['begin'])) self.assertIn("end", el.attrib) self.assertTrue(storage.TIME_EXPRESSION_CLOCK_TIME.match(el.attrib['end'])) self.assertNotIn('dur', el.attrib)
def test_load_from_dfxp(self): subs = self.loader.load('en', utils.get_data_file_path("simple.dfxp")) # since we are loading directly from DFXP, we should keep the # styling/layout the same as the file head = subs._ttml.find(TTML + 'head') styling = head.find(TTML + 'styling') styles = styling.findall(TTML + 'style') self.assertEquals(len(styles), 1) self.assertEquals(styles[0].attrib, { 'id': "defaultCaption", TTS + 'fontSize': "14px", TTS + 'fontFamily': "Arial", TTS + 'fontWeight': "normal", TTS + 'fontStyle': "normal", TTS + 'textDecoration': "none", TTS + 'color': "white", TTS + 'backgroundColor': "black", TTS + 'textAlign': "center", }) self.assertEquals(head.find(TTML + 'layout'), None)
def _get_subs(self, filename): return YoutubeParser( open(utils.get_data_file_path(filename)).read(), 'en').to_internal()
def test_type_specified(self): subs = load_from_file(utils.get_data_file_path("simple.srt"), type='srt') parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_from_string_requires_type(self): data = open(utils.get_data_file_path("simple-srt.badextension"), 'r').read() self.assertRaises(TypeError, load_from, data)
def test_from_string(self): subs = load_from(open(utils.get_data_file_path("simple-srt.badextension"), 'r').read() ,type='srt') parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_type_override(self): subs = load_from_file(utils.get_data_file_path("simple-srt.badextension"), type='srt') parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_type_guessing(self): subs = load_from_file(utils.get_data_file_path("simple.srt")) parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_type_override(self): subs = load_from_file( utils.get_data_file_path("simple-srt.badextension"), type='srt') parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_load_from_string(self): filename = utils.get_data_file_path('simple.dfxp') with open(filename) as f: s = f.read() load_from(s, type='dfxp').to_internal()
def test_load(self): subs = self.loader.load('en', utils.get_data_file_path("simple.srt")) self.check_srt_import(subs)
def test_cleanup_namespace(self): input_string = open(utils.get_data_file_path("pre-dmr.dfxp")).read() cleaned = _cleanup_legacy_namespace(input_string) self.assertEqual(cleaned.find(TTML_NAMESPACE_URI_LEGACY), -1) sset = SubtitleSet(language_code='en', initial_data=cleaned) self.assertEqual(len(sset), 419)
def _get_subs(self, filename): return YoutubeParser(open(utils.get_data_file_path(filename)).read(), 'en').to_internal()
def test_from_string(self): subs = load_from(open( utils.get_data_file_path("simple-srt.badextension"), 'r').read(), type='srt') parsed = subs.to_internal() self.assertEquals(len(parsed), 19)
def test_load_from_string(self): content = open(utils.get_data_file_path("simple.srt")).read() subs = self.loader.loads('en', content, 'srt') self.check_srt_import(subs)