コード例 #1
0
 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.assertEqual(caption.layout_info.alignment.horizontal,
                      HorizontalAlignmentEnum.RIGHT)
コード例 #2
0
 def test_sami_to_dfxp_xml_output(self):
     captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR)
     results = DFXPWriter(relativize=False,
                          fit_to_screen=False).write(captions)
     self.assertTrue(isinstance(results, six.text_type))
     self.assertTrue('xmlns="http://www.w3.org/ns/ttml"' in results)
     self.assertTrue(
         'xmlns:tts="http://www.w3.org/ns/ttml#styling"' in results)
コード例 #3
0
    def test_6digit_color_code_from_3digit_input(self):
        captions = SAMIReader().read(SAMPLE_SAMI.replace("#ffeedd", "#fed"))
        p_style = captions.get_style("p")

        self.assertEqual("#ffeedd", p_style['color'])
コード例 #4
0
 def test_empty_file(self):
     self.assertRaises(CaptionReadNoCaptions,
                       SAMIReader().read, SAMPLE_SAMI_EMPTY)
コード例 #5
0
    def test_caption_length(self):
        captions = SAMIReader().read(SAMPLE_SAMI)

        self.assertEqual(7, len(captions.get_captions("en-US")))
コード例 #6
0
    def test_proper_timestamps(self):
        captions = SAMIReader().read(SAMPLE_SAMI)
        paragraph = captions.get_captions("en-US")[2]

        self.assertEqual(17000000, paragraph.start)
        self.assertEqual(18752000, paragraph.end)
コード例 #7
0
 def test_sami_reader_only_supports_unicode_input(self):
     with self.assertRaises(InvalidInputError):
         SAMIReader().read(b'')
コード例 #8
0
 def test_detection(self):
     self.assertTrue(SAMIReader().detect(SAMPLE_SAMI))
コード例 #9
0
 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.assertEqual(caption.layout_info.alignment.horizontal,
                      HorizontalAlignmentEnum.RIGHT)
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
 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)
コード例 #13
0
 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)
コード例 #14
0
 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)
コード例 #15
0
 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)
コード例 #16
0
 def test_invalid_markup_is_properly_handled(self):
     captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR)
     self.assertEqual(2, len(captions.get_captions("en-US")))
コード例 #17
0
 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)
コード例 #18
0
 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.assertEqual(caption_set.layout_info.padding.to_xml_attribute(),
                      '0% 29pt 0% 29pt')
コード例 #19
0
 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)
コード例 #20
0
 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)
コード例 #21
0
 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, six.text_type))
     self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SAMI_WITH_ID_STYLE, results)