示例#1
0
    def test_merge_concurrent_captions(self):
        caption_set = DFXPReader().read(DFXP_WITH_CONCURRENT_CAPTIONS)
        captions = caption_set.get_captions('en-US')
        self.assertEqual(len(captions), 5)

        caption_set = merge_concurrent_captions(caption_set)
        captions = caption_set.get_captions('en-US')
        self.assertEqual(len(captions), 3)
示例#2
0
    def test_merge_concurrent_captions(self):
        caption_set = DFXPReader().read(DFXP_WITH_CONCURRENT_CAPTIONS)
        captions = caption_set.get_captions('en-US')
        self.assertEqual(len(captions), 5)

        caption_set = merge_concurrent_captions(caption_set)
        captions = caption_set.get_captions('en-US')
        self.assertEqual(len(captions), 3)
示例#3
0
 def test_properly_converts_timing(self):
     caption_set = DFXPReader().read(DFXP_WITH_ALTERNATIVE_TIMING_FORMATS)
     caps = caption_set.get_captions('en-US')
     self.assertEqual(caps[0].start, 1900000)
     self.assertEqual(caps[0].end, 3050000)
     self.assertEqual(caps[1].start, 4000000)
     self.assertEqual(caps[1].end, 5200000)
示例#4
0
    def test_properly_converts_frametiming(self,
                                           sample_dfxp_with_frame_timing):
        caption_set = DFXPReader().read(sample_dfxp_with_frame_timing)
        caps = caption_set.get_captions('en-US')

        assert caps[0].end == 12233333
        assert caps[0].start == 9666666
示例#5
0
 def test_individual_timings_of_captions_with_matching_timespec_are_kept(
         self):  # noqa
     captionset = DFXPReader().read(
         SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING)
     expected_timings = [(9209000, 12312000)] * 3
     actual_timings = [(c_.start, c_.end)
                       for c_ in captionset.get_captions('en-US')]
     self.assertEqual(expected_timings, actual_timings)
示例#6
0
    def test_merge_concurrent_captions(self, dfxp_with_concurrent_captions):
        initial_caption_set = DFXPReader().read(dfxp_with_concurrent_captions)
        initial_captions = initial_caption_set.get_captions('en-US')
        caption_set = merge_concurrent_captions(initial_caption_set)
        captions = caption_set.get_captions('en-US')

        assert len(initial_captions) == 5
        assert len(captions) == 3
示例#7
0
    def test_proper_xml_entity_escaping(
            self, sample_dfxp_with_escaped_apostrophe):
        caption_set = DFXPReader().read(sample_dfxp_with_escaped_apostrophe)
        cue_text = caption_set.get_captions('en-US')[0].nodes[0].content

        assert cue_text == "<< \"Andy's Caf\xe9 & Restaurant\" this way"
        result = DFXPWriter().write(caption_set)
        assert "&lt;&lt; \"Andy's Café &amp; Restaurant\" this way" in result
示例#8
0
 def test_proper_xml_entity_escaping(self):
     caption_set = DFXPReader().read(DFXP_WITH_ESCAPED_APOSTROPHE)
     cue_text = caption_set.get_captions(u'en-US')[0].nodes[0].content
     self.assertEqual(cue_text,
                      u"<< \"Andy's Caf\xe9 & Restaurant\" this way")
     result = DFXPWriter().write(caption_set)
     self.assertIn(u"&lt;&lt; \"Andy's Café &amp; Restaurant\" this way",
                   result)
示例#9
0
 def test_properly_converts_timing(self):
     caption_set = DFXPReader().read(
         DFXP_WITH_ALTERNATIVE_TIMING_FORMATS)
     caps = caption_set.get_captions('en-US')
     self.assertEqual(caps[0].start, 1900000)
     self.assertEqual(caps[0].end, 3050000)
     self.assertEqual(caps[1].start, 4000000)
     self.assertEqual(caps[1].end, 5200000)
示例#10
0
 def test_individual_timings_of_captions_with_matching_timespec_are_kept(self):  # noqa
     captionset = DFXPReader().read(
         SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
     )
     expected_timings = [(9209000, 12312000)] * 3
     actual_timings = [(c_.start, c_.end) for c_ in
                       captionset.get_captions('en-US')]
     self.assertEqual(expected_timings, actual_timings)
示例#11
0
 def test_properly_converts_timing_with_frames_with_30fps_default(self):
     caption_set = DFXPReader().read(SAMPLE_DFXP_FRAME_TIMING_DEFAULT_30FPS)
     caps = caption_set.get_captions('en-US')
     self.assertEqual(caps[0].start, 8100000)
     self.assertEqual(caps[0].end, 12190000)
     self.assertEqual(caps[1].start, 258066666)
     self.assertEqual(caps[1].end, 8168190000)
     self.assertEqual(caps[2].start, 43208966666)
     self.assertEqual(caps[2].end, 50412190000)
示例#12
0
 def test_properly_converts_timing_with_frames_with_25fps(self):
     caption_set = DFXPReader().read(SAMPLE_DFXP_FRAME_TIMING_25FPS)
     caps = caption_set.get_captions('en-US')
     self.assertEqual(caps[0].start, 8120000)
     self.assertEqual(caps[0].end, 12190000)
     self.assertEqual(caps[1].start, 258080000)
     self.assertEqual(caps[1].end, 8168190000)
     self.assertEqual(caps[2].start, 43208960000)
     self.assertEqual(caps[2].end, 50412190000)
示例#13
0
    def test_individual_timings_of_captions_with_matching_timespec_are_kept(
            self, sample_dfxp_multiple_captions_with_the_same_timing):
        captionset = DFXPReader().read(
            sample_dfxp_multiple_captions_with_the_same_timing)
        expected_timings = [(9209000, 12312000)] * 3
        actual_timings = [(c_.start, c_.end)
                          for c_ in captionset.get_captions('en-US')]

        assert expected_timings == actual_timings
示例#14
0
    def test_properly_converts_timing(
            self, sample_dfxp_with_alternative_timing_formats):
        caption_set = DFXPReader().read(
            sample_dfxp_with_alternative_timing_formats)
        caps = caption_set.get_captions('en-US')

        assert caps[0].start == 1900000
        assert caps[0].end == 3050000
        assert caps[1].start == 4000000
        assert caps[1].end == 5200000
 def test_proper_xml_entity_escaping(self):
     caption_set = DFXPReader().read(DFXP_WITH_ESCAPED_APOSTROPHE)
     cue_text = caption_set.get_captions(u'en-US')[0].nodes[0].content
     self.assertEqual(
         cue_text, u"<< \"Andy's Caf\xe9 & Restaurant\" this way")
     result = DFXPWriter().write(caption_set)
     self.assertIn(
         u"&lt;&lt; \"Andy's Café &amp; Restaurant\" this way",
         result
     )
示例#16
0
 def test_properly_converts_timing_with_frames_with_29_97fps_multiplier(
         self):
     caption_set = DFXPReader().read(
         SAMPLE_DFXP_FRAME_TIMING_MULTIPLIER_29_97FPS)
     caps = caption_set.get_captions('en-US')
     self.assertEqual(caps[0].start, 8100100)
     self.assertEqual(caps[0].end, 12190000)
     self.assertEqual(caps[1].start, 258066733)
     self.assertEqual(caps[1].end, 8168190000)
     self.assertEqual(caps[2].start, 43208967633)
     self.assertEqual(caps[2].end, 50412190000)
示例#17
0
    def test_individual_layouts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )
        expected_layouts = [
            (((10, UnitEnum.PERCENT), (10, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((40, UnitEnum.PERCENT), (40, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((10, UnitEnum.PERCENT), (70, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM))]
        actual_layouts = [c_.layout_info.serialized() for c_ in
                          captionset.get_captions('en-US')]

        self.assertEqual(expected_layouts, actual_layouts)
示例#18
0
    def test_individual_layouts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )
        expected_layouts = [
            (((10, UnitEnum.PERCENT), (10, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((40, UnitEnum.PERCENT), (40, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((10, UnitEnum.PERCENT), (70, UnitEnum.PERCENT)), None, None, (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM))]
        actual_layouts = [c_.layout_info.serialized() for c_ in
                          captionset.get_captions('en-US')]

        self.assertEqual(expected_layouts, actual_layouts)
示例#19
0
    def test_individual_texts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )

        expected_texts = ['Some text here',
                          'Some text there',
                          'Caption texts are everywhere!']
        actual_texts = [c_.nodes[0].content for c_ in
                        captionset.get_captions("en-US")]

        self.assertEqual(expected_texts, actual_texts)
示例#20
0
    def test_individual_layouts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )
        expected_layouts = [
            (((10, u'%'), (10, u'%')), None, None, (u'center', u'bottom')),
            (((40, u'%'), (40, u'%')), None, None, (u'center', u'bottom')),
            (((10, u'%'), (70, u'%')), None, None, (u'center', u'bottom'))]
        actual_layouts = [c_.layout_info.serialized() for c_ in
                          captionset.get_captions('en-US')]

        self.assertEqual(expected_layouts, actual_layouts)
示例#21
0
    def test_individual_layouts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )
        expected_layouts = [
            (((10, u'%'), (10, u'%')), None, None, (u'center', u'bottom')),
            (((40, u'%'), (40, u'%')), None, None, (u'center', u'bottom')),
            (((10, u'%'), (70, u'%')), None, None, (u'center', u'bottom'))]
        actual_layouts = [c_.layout_info.serialized() for c_ in
                          captionset.get_captions('en-US')]

        self.assertEqual(expected_layouts, actual_layouts)
示例#22
0
    def test_individual_texts_of_captions_with_matching_timespec_are_kept(self):  # noqa
        captionset = DFXPReader().read(
            SAMPLE_DFXP_MULTIPLE_CAPTIONS_WITH_THE_SAME_TIMING
        )

        expected_texts = [u'Some text here',
                          u'Some text there',
                          u'Caption texts are everywhere!']
        actual_texts = [c_.nodes[0].content for c_ in
                        captionset.get_captions("en-US")]

        self.assertEqual(expected_texts, actual_texts)
示例#23
0
    def test_individual_texts_of_captions_with_matching_timespec_are_kept(
            self, sample_dfxp_multiple_captions_with_the_same_timing):
        captionset = DFXPReader().read(
            sample_dfxp_multiple_captions_with_the_same_timing)

        expected_texts = [
            'Some text here', 'Some text there',
            'Caption texts are everywhere!'
        ]
        actual_texts = [
            c_.nodes[0].content for c_ in captionset.get_captions("en-US")
        ]

        assert expected_texts == actual_texts
示例#24
0
    def test_individual_layouts_of_captions_with_matching_timespec_are_kept(
            self, sample_dfxp_multiple_captions_with_the_same_timing):
        captionset = DFXPReader().read(
            sample_dfxp_multiple_captions_with_the_same_timing)
        expected_layouts = [
            (((10, UnitEnum.PERCENT), (10, UnitEnum.PERCENT)), None, None,
             (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((40, UnitEnum.PERCENT), (40, UnitEnum.PERCENT)), None, None,
             (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM)),
            (((10, UnitEnum.PERCENT), (70, UnitEnum.PERCENT)), None, None,
             (HorizontalAlignmentEnum.CENTER, VerticalAlignmentEnum.BOTTOM))
        ]
        actual_layouts = [
            c_.layout_info.serialized()
            for c_ in captionset.get_captions('en-US')
        ]

        assert expected_layouts == actual_layouts
示例#25
0
    def test_proper_timestamps(self):
        captions = DFXPReader().read(SAMPLE_DFXP.decode(u'utf-8'))
        paragraph = captions.get_captions(u"en-US")[2]

        self.assertEquals(17000000, paragraph.start)
        self.assertEquals(18752000, paragraph.end)
示例#26
0
 def test_caption_length(self):
     captions = DFXPReader().read(SAMPLE_DFXP.decode(u'utf-8'))
     self.assertEquals(8, len(captions.get_captions(u"en-US")))
示例#27
0
 def test_empty_cue(self):
     caption_set = DFXPReader().read(
         SAMPLE_DFXP_EMPTY_CUE)
     caps = caption_set.get_captions('en-US')
     self.assertEquals(caps[1], [])
示例#28
0
    def test_invalid_markup_is_properly_handled(self,
                                                sample_dfxp_syntax_error):
        captions = DFXPReader().read(sample_dfxp_syntax_error)

        assert 2 == len(captions.get_captions("en"))
示例#29
0
    def test_caption_length(self, sample_dfxp):
        captions = DFXPReader().read(sample_dfxp)

        assert 7 == len(captions.get_captions("en-US"))
示例#30
0
    def test_empty_cue(self, sample_dfxp_empty_cue):
        caption_set = DFXPReader().read(sample_dfxp_empty_cue)
        caps = caption_set.get_captions('en-US')

        assert len(caps) == 1
示例#31
0
 def test_caption_length(self):
     captions = DFXPReader().read(SAMPLE_DFXP)
     self.assertEqual(7, len(captions.get_captions("en-US")))
示例#32
0
 def test_caption_length(self):
     captions = DFXPReader().read(SAMPLE_DFXP)
     self.assertEquals(7, len(captions.get_captions(u"en-US")))
示例#33
0
 def test_caption_length(self):
     captions = DFXPReader().read(SAMPLE_DFXP.decode(u'utf-8'))
     self.assertEquals(8, len(captions.get_captions(u"en-US")))
示例#34
0
 def test_invalid_markup_is_properly_handled(self):
     captions = DFXPReader().read(SAMPLE_DFXP_SYNTAX_ERROR.decode(u'utf-8'))
     self.assertEquals(2, len(captions.get_captions(u"en-US")))
示例#35
0
    def test_proper_timestamps(self, sample_dfxp):
        captions = DFXPReader().read(sample_dfxp)
        paragraph = captions.get_captions("en-US")[2]

        assert 17000000 == paragraph.start
        assert 18752000 == paragraph.end
示例#36
0
    def test_proper_timestamps(self):
        captions = DFXPReader().read(SAMPLE_DFXP.decode(u'utf-8'))
        paragraph = captions.get_captions(u"en-US")[2]

        self.assertEquals(17000000, paragraph.start)
        self.assertEquals(18752000, paragraph.end)
示例#37
0
 def test_invalid_markup_is_properly_handled(self):
     captions = DFXPReader().read(SAMPLE_DFXP_SYNTAX_ERROR.decode(u'utf-8'))
     self.assertEquals(2, len(captions.get_captions(u"en-US")))