Ejemplo n.º 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)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
 def test_proper_xml_entity_escaping(self):
     caption_set = DFXPReader().read(DFXP_WITH_ESCAPED_APOSTROPHE)
     cue_text = caption_set.get_captions('en-US')[0].nodes[0].content
     self.assertEqual(cue_text,
                      "<< \"Andy's Caf\xe9 & Restaurant\" this way")
     result = DFXPWriter().write(caption_set)
     self.assertIn("&lt;&lt; \"Andy's Café &amp; Restaurant\" this way",
                   result)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
 def test_invalid_markup_is_properly_handled(self):
     captions = DFXPReader().read(SAMPLE_DFXP_SYNTAX_ERROR)
     self.assertEqual(2, len(captions.get_captions("en-US")))
Ejemplo n.º 8
0
    def test_proper_timestamps(self):
        captions = DFXPReader().read(SAMPLE_DFXP)
        paragraph = captions.get_captions("en-US")[2]

        self.assertEqual(17000000, paragraph.start)
        self.assertEqual(18752000, paragraph.end)
Ejemplo n.º 9
0
 def test_caption_length(self):
     captions = DFXPReader().read(SAMPLE_DFXP)
     self.assertEqual(7, len(captions.get_captions("en-US")))
Ejemplo n.º 10
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], [])