def test_sami_to_dfxp_with_span(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_SPAN) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertDFXPEquals(SAMPLE_DFXP_FROM_SAMI_WITH_SPAN, results)
def test_double_br(self): caption_set = SAMIReader().read(SAMPLE_SAMI_DOUBLE_BR) results = WebVTTWriter().write(caption_set) self.assertEqual(SAMPLE_WEBVTT_DOUBLE_BR, results)
def test_is_relativized(self): # Absolute positioning settings (e.g. px) are converted to percentages caption_set = SAMIReader().read(SAMPLE_SAMI_PARTIAL_MARGINS) result = SAMIWriter(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT).write(caption_set) self.assertSAMIEquals(result, SAMPLE_SAMI_PARTIAL_MARGINS_RELATIVIZED)
def test_sami_to_dfxp_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertDFXPEquals(DFXP_FROM_SAMI_WITH_POSITIONING, results)
def test_sami_with_p_align(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_P_ALIGN) caption = caption_set.get_captions('en-US')[0] self.assertEquals(caption.layout_info.alignment.horizontal, HorizontalAlignmentEnum.RIGHT)
def test_sami_to_sami_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI_NO_LANG) results = SAMIWriter().write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertSAMIEquals(SAMPLE_SAMI_WITH_LANG, results) self.assertTrue("lang: en-US;" in results)
def test_caption_length(self): captions = SAMIReader().read(SAMPLE_SAMI) self.assertEquals(7, len(captions.get_captions("en-US")))
def test_6digit_color_code_from_3digit_input(self): captions = SAMIReader().read(SAMPLE_SAMI.replace("#ffeedd", "#fed")) p_style = captions.get_style("p") self.assertEquals("#ffeedd", p_style[u'color'])
def test_sami_with_p_and_span_align(self): """ <span> align DOES NOT override <p> align if it is specified inline. """ caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_P_AND_SPAN_ALIGN) caption = caption_set.get_captions('en-US')[0] self.assertEquals(caption.layout_info.alignment.horizontal, HorizontalAlignmentEnum.RIGHT)
def test_proper_pcc_format(self): captions = SAMIReader().read(SAMPLE_SAMI) self.assertEquals(set(["captions", "styles"]), set(captions.keys())) self.assertEquals(7, len(captions["captions"]["en-US"]))
def test_6digit_color_code_from_6digit_input(self): captions = SAMIReader().read(SAMPLE_SAMI) p_style = captions.get_style(u"p") self.assertEquals(u"#ffeedd", p_style[u'color'])
def test_6digit_color_code_from_3digit_input(self): captions = SAMIReader().read(SAMPLE_SAMI.decode(u"utf-8").replace(u"#ffeedd", u"#fed")) p_style = captions.get_style(u"p") self.assertEquals(u"#ffeedd", p_style[u"color"])
def test_sami_reader_only_supports_unicode_input(self): with self.assertRaises(InvalidInputError): SAMIReader().read('')
def test_proper_timestamps(self): captions = SAMIReader().read(SAMPLE_SAMI) paragraph = captions.get_captions("en-US")[2] self.assertEquals(17000000, paragraph.start) self.assertEquals(18752000, paragraph.end)
def test_6digit_color_code_from_3digit_input(self): captions = SAMIReader().read(SAMPLE_SAMI.replace("#ffeedd", "#fed")) p_style = captions.get_style("p") self.assertEquals("#ffeedd", p_style['color'])
def test_invalid_markup_is_properly_handled(self): captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR) self.assertEquals(2, len(captions.get_captions("en-US")))
def test_caption_length(self): captions = SAMIReader().read(SAMPLE_SAMI.decode(u"utf-8")) self.assertEquals(8, len(captions.get_captions(u"en-US")))
def test_caption_length(self, sample_sami): captions = SAMIReader().read(sample_sami) assert 7 == len(captions.get_captions("en-US"))
def test_sami_to_sami_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI) results = SAMIWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertSAMIEquals(SAMPLE_SAMI, results)
def test_proper_timestamps(self, sample_sami): captions = SAMIReader().read(sample_sami) paragraph = captions.get_captions("en-US")[2] assert 17000000 == paragraph.start assert 18752000 == paragraph.end
def test_sami_to_srt_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI) results = SRTWriter().write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertSRTEquals(SAMPLE_SRT, results)
def test_6digit_color_code_from_6digit_input(self, sample_sami): captions = SAMIReader().read(sample_sami) p_style = captions.get_style("p") assert "#ffeedd" == p_style['color']
def test_sami_to_dfxp_with_margin_for_language(self): caption_set = SAMIReader().read(SAMPLE_SAMI_LANG_MARGIN) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertDFXPEquals(SAMPLE_DFXP_FROM_SAMI_WITH_LANG_MARGINS, results)
def test_6digit_color_code_from_3digit_input(self, sample_sami): sample_sami = deepcopy(sample_sami) captions = SAMIReader().read(sample_sami.replace("#ffeedd", "#fed")) p_style = captions.get_style("p") assert "#ffeedd" == p_style['color']
def test_sami_to_dfxp_ignores_multiple_span_aligns(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_MULTIPLE_SPAN_ALIGNS) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertDFXPEquals(SAMPLE_DFXP_FROM_SAMI_WITH_BAD_SPAN_ALIGN, results)
def test_empty_file(self, sample_sami_empty): with pytest.raises(CaptionReadNoCaptions): SAMIReader().read(sample_sami_empty)
def build_sami_reader(): return SubtitleReader(SAMIReader())
def test_invalid_markup_is_properly_handled(self, sample_sami_syntax_error): captions = SAMIReader().read(sample_sami_syntax_error) assert 2 == len(captions.get_captions("en-US"))
def test_detection(self): self.assertTrue(SAMIReader().detect(SAMPLE_SAMI))
def test_sami_with_p_align(self, sample_sami_with_p_align): caption_set = SAMIReader().read(sample_sami_with_p_align) caption = caption_set.get_captions('en-US')[0] assert caption.layout_info.alignment.horizontal == \ HorizontalAlignmentEnum.RIGHT
def test_detection(self, sample_sami): assert SAMIReader().detect(sample_sami) is True
def test_empty_file(self): self.assertRaises(CaptionReadNoCaptions, SAMIReader().read, SAMPLE_SAMI_EMPTY)
def test_double_br(self): captions = SAMIReader().read(SAMPLE_SAMI_DOUBLE_BR.decode(u'utf-8')) self.assertEqual(SAMPLE_WEBVTT_DOUBLE_BR.decode(u'utf-8'), self.writer.write(captions))
def test_partial_margins(self): caption_set = SAMIReader().read(SAMPLE_SAMI_PARTIAL_MARGINS) # Ensure that undefined margins are converted to explicitly nil padding # (i.e. "0%") self.assertEquals(caption_set.layout_info.padding.to_xml_attribute(), u'0% 29pt 0% 29pt')
def test_sami_with_style_tags_to_webvtt_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_STYLE_TAGS) results = WebVTTWriter(video_width=640, video_height=360).write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SAMI_WITH_STYLE, results)
def test_sami_with_css_id_style_to_webvtt_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_CSS_ID_STYLE) results = WebVTTWriter(video_width=640, video_height=360).write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SAMI_WITH_ID_STYLE, results)
def test_sami_with_bad_div_align(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_BAD_DIV_ALIGN) caption = caption_set.get_captions('en-US')[0] self.assertEquals(caption.layout_info.alignment.horizontal, u'right')