def test_webvtt_to_dfxp_conversion(self):
     caption_set = WebVTTReader().read(SAMPLE_WEBVTT)
     results = DFXPWriter().write(caption_set)
     self.assertTrue(isinstance(results, six.text_type))
     self.assertDFXPEquals(
         SAMPLE_DFXP, results, ignore_styling=True, ignore_spans=True
     )
Esempio n. 2
0
 def test_fit_to_screen(self):
     # Check if caption width and height are is explicitly set and
     # recalculate it if necessary. This prevents long captions from being
     # cut out of the screen.
     caption_set = DFXPReader().read(SAMPLE_DFXP_LONG_CUE)
     result = DFXPWriter().write(caption_set)
     self.assertEqual(result, SAMPLE_DFXP_LONG_CUE_FIT_TO_SCREEN)
Esempio n. 3
0
    def test_default_styling_p_tags(self):
        caption_set = DFXPReader().read(SAMPLE_DFXP)
        result = DFXPWriter().write(caption_set)

        soup = BeautifulSoup(result, 'lxml')
        for p in soup.find_all('p'):
            self.assertEqual(p.attrs.get('style'), 'p')
Esempio n. 4
0
    def test_default_region_p_tags(self):
        caption_set = DFXPReader().read(SAMPLE_DFXP)
        result = DFXPWriter().write(caption_set)

        soup = BeautifulSoup(result, 'lxml')
        for p in soup.find_all('p'):
            self.assertEqual(p.attrs.get('region'), DFXP_DEFAULT_REGION_ID)
 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)
Esempio n. 6
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)
Esempio n. 7
0
 def test_dont_create_style_tags_with_no_id(self):
     # The <style> tags can have no 'xml:id' attribute. Previously, in this
     # case, the style was copied to the output file, with the 'xml:id'
     # property declared, but no value assigned to it. Since such a style
     # can not be referred anyway, and <style> elements, children of
     # <region> tags shouldn't be referred to anyway, we don't include
     # these styles in the output file
     caption_set = DFXPReader().read(
         SAMPLE_DFXP_STYLE_TAG_WITH_NO_XML_ID_INPUT)
     result = DFXPWriter().write(caption_set)
     self.assertEqual(result, SAMPLE_DFXP_STYLE_TAG_WITH_NO_XML_ID_OUTPUT)
Esempio n. 8
0
    def test_default_styling_tag(self):
        caption_set = DFXPReader().read(SAMPLE_DFXP_WITHOUT_REGION_AND_STYLE)
        result = DFXPWriter().write(caption_set)

        default_style = _recreate_style(DFXP_DEFAULT_STYLE, None)
        default_style['xml:id'] = DFXP_DEFAULT_STYLE_ID

        soup = BeautifulSoup(result, 'lxml-xml')
        style = soup.find('style', {'xml:id': DFXP_DEFAULT_STYLE_ID})

        self.assertTrue(style)
        self.assertEqual(style.attrs, default_style)
Esempio n. 9
0
    def test_default_region_tag(self):
        caption_set = DFXPReader().read(SAMPLE_DFXP)
        result = DFXPWriter().write(caption_set)

        soup = BeautifulSoup(result, 'lxml-xml')
        region = soup.find('region', {'xml:id': DFXP_DEFAULT_REGION_ID})

        default_region = _convert_layout_to_attributes(DFXP_DEFAULT_REGION)
        default_region['xml:id'] = DFXP_DEFAULT_REGION_ID

        self.assertTrue(region)
        self.assertEqual(region.attrs['xml:id'], DFXP_DEFAULT_REGION_ID)
        self.assertEqual(region.attrs, default_region)
Esempio n. 10
0
    def test_incorrectly_specified_positioning_is_explicitly_accepted(self):
        # The arguments used here illustrate how we will try to read
        # and write incorrectly specified positioning information.
        # By incorrect, I mean the specs say that those attributes should be
        # ignored, not that the attributes themselves are outside of the specs
        caption_set = DFXPReader(read_invalid_positioning=True).read(
            SAMPLE_DFXP_INVALID_BUT_SUPPORTED_POSITIONING_INPUT)
        result = DFXPWriter(relativize=False,
                            fit_to_screen=False,
                            write_inline_positioning=True).write(caption_set)

        if six.PY2:
            self.assertDFXPEquals(
                result, SAMPLE_DFXP_INVALID_BUT_SUPPORTED_POSITIONING_OUTPUT)
        else:
            # attributes are sorted differently I guess testing for same
            # length is close enough
            self.assertDFXPEquals(
                result, SAMPLE_DFXP_INVALID_BUT_SUPPORTED_POSITIONING_OUTPUT)
 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_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)
Esempio n. 13
0
 def test_dfxp_to_dfxp_conversion(self):
     caption_set = DFXPReader().read(SAMPLE_DFXP)
     results = DFXPWriter().write(caption_set)
     self.assertTrue(isinstance(results, text_type))
     self.assertDFXPEquals(SAMPLE_DFXP_OUTPUT, results)
 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_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)
Esempio n. 16
0
 def test_is_relativized(self):
     # Absolute positioning settings (e.g. px) are converted to percentages
     caption_set = DFXPReader().read(SAMPLE_DFXP_WITH_POSITIONING)
     result = DFXPWriter(video_width=VIDEO_WIDTH,
                         video_height=VIDEO_HEIGHT).write(caption_set)
     self.assertEqual(result, SAMPLE_DFXP_WITH_RELATIVIZED_POSITIONING)
    def test_dfxp_is_valid_xml_when_scc_source_has_weird_italic_commands(self):
        caption_set = SCCReader().read(
            SAMPLE_SCC_CREATED_DFXP_WITH_WRONGLY_CLOSING_SPANS)

        dfxp = DFXPWriter().write(caption_set)
        self.assertEqual(dfxp, SAMPLE_DFXP_WITH_PROPERLY_CLOSING_SPANS_OUTPUT)
Esempio n. 18
0
 def test_correct_region_attributes_are_recreated(self):
     caption_set = DFXPReader().read(SAMPLE_DFXP_MULTIPLE_REGIONS_INPUT)
     result = DFXPWriter(relativize=False,
                         fit_to_screen=False).write(caption_set)
     self.assertDFXPEquals(result, SAMPLE_DFXP_MULTIPLE_REGIONS_OUTPUT)
 def test_scc_to_dfxp(self):
     caption_set = SCCReader().read(SAMPLE_SCC_MULTIPLE_POSITIONING)
     dfxp = DFXPWriter(relativize=False,
                       fit_to_screen=False).write(caption_set)
     self.assertEqual(SAMPLE_DFXP_FROM_SCC_OUTPUT, dfxp)