예제 #1
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)
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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.assertEquals(caption.layout_info.alignment.horizontal,
                       HorizontalAlignmentEnum.RIGHT)
예제 #6
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)
예제 #7
0
    def test_caption_length(self):
        captions = SAMIReader().read(SAMPLE_SAMI)

        self.assertEquals(7, len(captions.get_captions("en-US")))
예제 #8
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.assertEquals("#ffeedd", p_style[u'color'])
예제 #9
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.assertEquals(caption.layout_info.alignment.horizontal, HorizontalAlignmentEnum.RIGHT)
예제 #10
0
    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"]))
예제 #11
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.assertEquals(caption.layout_info.alignment.horizontal, HorizontalAlignmentEnum.RIGHT)
예제 #12
0
    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'])
예제 #13
0
파일: test_sami.py 프로젝트: vhx/pycaption
    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"])
예제 #14
0
 def test_sami_reader_only_supports_unicode_input(self):
     with self.assertRaises(InvalidInputError):
         SAMIReader().read('')
예제 #15
0
    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)
예제 #16
0
    def test_caption_length(self):
        captions = SAMIReader().read(SAMPLE_SAMI)

        self.assertEquals(7, len(captions.get_captions("en-US")))
예제 #17
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.assertEquals("#ffeedd", p_style['color'])
예제 #18
0
 def test_invalid_markup_is_properly_handled(self):
     captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR)
     self.assertEquals(2, len(captions.get_captions("en-US")))
예제 #19
0
 def test_invalid_markup_is_properly_handled(self):
     captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR)
     self.assertEquals(2, len(captions.get_captions("en-US")))
예제 #20
0
파일: test_sami.py 프로젝트: vhx/pycaption
    def test_caption_length(self):
        captions = SAMIReader().read(SAMPLE_SAMI.decode(u"utf-8"))

        self.assertEquals(8, len(captions.get_captions(u"en-US")))
예제 #21
0
    def test_caption_length(self, sample_sami):
        captions = SAMIReader().read(sample_sami)

        assert 7 == len(captions.get_captions("en-US"))
예제 #22
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)
예제 #23
0
    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
예제 #24
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)
예제 #25
0
    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']
예제 #26
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)
예제 #27
0
    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']
예제 #28
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)
예제 #29
0
 def test_empty_file(self, sample_sami_empty):
     with pytest.raises(CaptionReadNoCaptions):
         SAMIReader().read(sample_sami_empty)
예제 #30
0
def build_sami_reader():
    return SubtitleReader(SAMIReader())
예제 #31
0
    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"))
예제 #32
0
 def test_detection(self):
     self.assertTrue(SAMIReader().detect(SAMPLE_SAMI))
예제 #33
0
    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
예제 #34
0
    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)
예제 #35
0
 def test_detection(self, sample_sami):
     assert SAMIReader().detect(sample_sami) is True
예제 #36
0
 def test_empty_file(self):
     self.assertRaises(CaptionReadNoCaptions,
                       SAMIReader().read, SAMPLE_SAMI_EMPTY)
예제 #37
0
    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))
예제 #38
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.assertEquals(caption_set.layout_info.padding.to_xml_attribute(),
                       u'0% 29pt 0% 29pt')
예제 #39
0
 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)
예제 #40
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, unicode))
     self.assertWebVTTEquals(SAMPLE_WEBVTT_FROM_SAMI_WITH_ID_STYLE, results)
예제 #41
0
 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')