def test_default_region_p_tags(self): w = DFXPWriter() result = w.write(self.captions) soup = BeautifulSoup(result, u'xml') for p in soup.find_all(u'p'): self.assertEquals(p.attrs.get(u'region'), DFXP_DEFAULT_REGION_ID)
def test_default_styling_p_tags(self): w = DFXPWriter() result = w.write(self.captions) soup = BeautifulSoup(result, u'xml') for p in soup.find_all(u'p'): self.assertEquals(p.attrs.get(u'style'), 'p')
def test_default_styling_tag(self): w = DFXPWriter() result = w.write(self.captions_without_style_and_region) default_style = _recreate_style(DFXP_DEFAULT_STYLE, None) default_style[u'xml:id'] = DFXP_DEFAULT_STYLE_ID soup = BeautifulSoup(result, u'xml') style = soup.find(u'style', {u'xml:id': DFXP_DEFAULT_STYLE_ID}) self.assertTrue(style) self.assertEquals(style.attrs, default_style)
def test_default_region_tag(self): w = DFXPWriter() result = w.write(self.captions) default_region = w._recreate_style(DFXP_DEFAULT_REGION, None) default_region[u'xml:id'] = DFXP_DEFAULT_REGION_ID soup = BeautifulSoup(result, u'xml') region = soup.find(u'region', {u'xml:id': DFXP_DEFAULT_REGION_ID}) self.assertTrue(region) self.assertEquals(region.attrs, default_region)
def test_default_region_tag(self): w = DFXPWriter() result = w.write(self.captions) soup = BeautifulSoup(result, u'xml') region = soup.find(u'region', {u'xml:id': DFXP_DEFAULT_REGION_ID}) default_region = _convert_layout_to_attributes(DFXP_DEFAULT_REGION) default_region[u'xml:id'] = DFXP_DEFAULT_REGION_ID self.assertTrue(region) self.assertEquals(region.attrs[u'xml:id'], DFXP_DEFAULT_REGION_ID) self.assertEqual(region.attrs, default_region)
def test_sami_to_dfxp_with_span(self, sample_dfxp_from_sami_with_span, sample_sami_with_span): caption_set = SAMIReader().read(sample_sami_with_span) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assert_dfxp_equals(sample_dfxp_from_sami_with_span, results)
def test_scc_to_dfxp(self, sample_dfxp_from_scc_output, sample_scc_multiple_positioning): caption_set = SCCReader().read(sample_scc_multiple_positioning) dfxp = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) assert sample_dfxp_from_scc_output == dfxp
def test_sami_to_dfxp_xml_output(self): captions = SAMIReader().read(SAMPLE_SAMI_SYNTAX_ERROR.decode('utf-8')) results = DFXPWriter().write(captions) self.assertTrue(isinstance(results, unicode)) self.assertTrue(u'xmlns="http://www.w3.org/ns/ttml"' in results) self.assertTrue( u'xmlns:tts="http://www.w3.org/ns/ttml#styling"' in results)
def test_default_region_p_tags(self): caption_set = DFXPReader().read(SAMPLE_DFXP) result = DFXPWriter().write(caption_set) soup = BeautifulSoup(result, u'xml') for p in soup.find_all(u'p'): self.assertEquals(p.attrs.get(u'region'), DFXP_DEFAULT_REGION_ID)
def test_is_relativized(self): # Absolute positioning settings (e.g. px) are converted to percentages caption_set = DFXPReader().read( SAMPLE_DFXP_WITH_POSITIONING.decode('utf-8')) result = DFXPWriter(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT).write(caption_set) self.assertEqual(result, SAMPLE_DFXP_WITH_RELATIVIZED_POSITIONING)
def test_default_styling_p_tags(self): caption_set = DFXPReader().read(SAMPLE_DFXP) result = DFXPWriter().write(caption_set) soup = BeautifulSoup(result, u'xml') for p in soup.find_all(u'p'): self.assertEquals(p.attrs.get(u'style'), 'p')
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)
def test_srt_to_dfxp_unicode_conversion(self): results = DFXPWriter().write(self.captions_unicode) self.assertTrue(isinstance(results, unicode)) self.assertDFXPEquals(SAMPLE_DFXP_UNICODE, results, ignore_styling=True, ignore_spans=True)
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_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"<< \"Andy's Café & Restaurant\" this way", result)
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)
def test_default_region_p_tags(self, sample_dfxp): caption_set = DFXPReader().read(sample_dfxp) result = DFXPWriter().write(caption_set) soup = BeautifulSoup(result, 'lxml') for p in soup.find_all('p'): assert p.attrs.get('region') == DFXP_DEFAULT_REGION_ID
def test_correct_region_attributes_are_recreated( self, sample_dfxp_multiple_regions_output, sample_dfxp_multiple_regions_input): caption_set = DFXPReader().read(sample_dfxp_multiple_regions_input) result = DFXPWriter( relativize=False, fit_to_screen=False).write(caption_set) self.assert_dfxp_equals(result, sample_dfxp_multiple_regions_output)
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 "<< \"Andy's Café & Restaurant\" this way" in result
def test_default_styling_p_tags(self, sample_dfxp): caption_set = DFXPReader().read(sample_dfxp) result = DFXPWriter().write(caption_set) soup = BeautifulSoup(result, 'lxml') for p in soup.find_all('p'): assert p.attrs.get('style') == 'p'
def test_dfxp_is_valid_xml_when_scc_source_has_ampersand_character( self, sample_dfxp_with_ampersand_character, sample_scc_with_ampersand_character): caption_set = SCCReader().read(sample_scc_with_ampersand_character) dfxp = DFXPWriter().write(caption_set) assert dfxp == sample_dfxp_with_ampersand_character
def test_webvtt_to_dfxp_conversion(self): caption_set = WebVTTReader().read(SAMPLE_WEBVTT.decode(u'utf-8')) results = DFXPWriter().write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertDFXPEquals(SAMPLE_DFXP_UNICODE, results, ignore_styling=True, ignore_spans=True)
def test_sami_to_dfxp_with_bad_span_align(self): caption_set = SAMIReader().read(SAMPLE_SAMI_WITH_BAD_SPAN_ALIGN) results = DFXPWriter( relativize=False, fit_to_screen=False).write(caption_set) self.assertDFXPEquals( SAMPLE_DFXP_FROM_SAMI_WITH_BAD_SPAN_ALIGN, results )
def test_srt_to_dfxp_conversion(self): caption_set = SRTReader().read(SAMPLE_SRT) results = DFXPWriter().write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertDFXPEquals(SAMPLE_DFXP, results, ignore_styling=True, ignore_spans=True)
def test_sami_to_dfxp_xml_output(self, sample_sami_syntax_error): captions = SAMIReader().read(sample_sami_syntax_error) results = DFXPWriter(relativize=False, fit_to_screen=False).write(captions) assert isinstance(results, str) assert 'xmlns="http://www.w3.org/ns/ttml"' in results assert 'xmlns:tts="http://www.w3.org/ns/ttml#styling"' in results
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)
def test_is_relativized(self, sample_dfxp_with_relativized_positioning, sample_dfxp_with_positioning): # 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) assert result == sample_dfxp_with_relativized_positioning
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, unicode)) self.assertDFXPEquals( DFXP_FROM_SAMI_WITH_POSITIONING, results )
def test_sami_to_dfxp_with_margin_for_language( self, sample_dfxp_from_sami_with_lang_margins, sample_sami_lang_margin): caption_set = SAMIReader().read(sample_sami_lang_margin) results = DFXPWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assert_dfxp_equals(sample_dfxp_from_sami_with_lang_margins, results)
def test_fit_to_screen(self, sample_dfxp_long_cue_fit_to_screen, sample_dfxp_long_cue): # 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) assert result == sample_dfxp_long_cue_fit_to_screen