def test_trimmed_1(self): tt = bindings.tt( sequenceIdentifier='testSequence001', sequenceNumber='1', timeBase='clock', extent='800px 600px', clockMode='local', lang='en-GB' ) head_elem = bindings.head_type( metadata.headMetadata_type( metadata.documentMetadata() ), bindings.styling( bindings.style_type( id='style1', fontSize='12px' ), bindings.style_type( id='style2', fontSize='15px' ), bindings.style_type( id='style3', color='red', fontSize='12px' ), bindings.style_type( id='style4', backgroundColor='blue' ) ), bindings.layout( bindings.region_type( id='region1', origin='200px 450px', extent='300px 150px', style=['style3'] ) ) ) body_elem = bindings.body_type( bindings.div_type( bindings.p_type( bindings.span_type( 'Some example text...', begin=datatypes.LimitedClockTimingType(timedelta(seconds=1)), end=datatypes.LimitedClockTimingType(timedelta(seconds=2)), style=['style4'], id='span1' ), bindings.br_type(), bindings.span_type( 'And another line', begin=datatypes.LimitedClockTimingType(timedelta(seconds=3)), end=datatypes.LimitedClockTimingType(timedelta(seconds=4)), id='span2' ), id='ID005' ), style=['style1'], region='region1' ), begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)), dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)), style=['style2'] ) tt.head = head_elem tt.body = body_elem document = EBUTT3Document.create_from_raw_binding(binding=tt) document.validate() self.assertIsInstance(document.get_element_by_id('region1'), bindings.region_type) self.assertIsInstance(document.get_element_by_id('style1'), bindings.style_type) self.assertIsInstance(document.get_element_by_id('style2'), bindings.style_type) self.assertIsInstance(document.get_element_by_id('style3'), bindings.style_type) self.assertIsInstance(document.get_element_by_id('style4'), bindings.style_type) self.assertIsInstance(document.get_element_by_id('ID005'), bindings.p_type) self.assertIsInstance(document.get_element_by_id('span1'), bindings.span_type) self.assertIsInstance(document.get_element_by_id('span2'), bindings.span_type) cdoc = document.extract_segment(deconflict_ids=True, begin=timedelta(seconds=2.5)) self.assertIsInstance(cdoc.get_element_by_id('SEQ1.region1'), bindings.region_type) self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style1'), bindings.style_type) self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style2'), bindings.style_type) self.assertIsInstance(cdoc.get_element_by_id('SEQ1.style3'), bindings.style_type) self.assertRaises(LookupError, cdoc.get_element_by_id, 'SEQ1.style4') self.assertIsInstance(cdoc.get_element_by_id('SEQ1.ID005'), bindings.p_type) self.assertRaises(LookupError, cdoc.get_element_by_id, 'SEQ1.span1') self.assertIsInstance(cdoc.get_element_by_id('SEQ1.span2'), bindings.span_type)
class TestReplaceStylesAndRegions(TestCase): tt = bindings.tt(sequenceIdentifier='testSequence001', sequenceNumber='1', timeBase='clock', extent='800px 600px', clockMode='local', lang='en-GB') head_elem = bindings.head_type( metadata.headMetadata_type(metadata.documentMetadata()), bindings.styling( bindings.style_type(id='SEQ58.defaultStyle1', fontSize='12px', color='rgb(255,255,255)', backgroundColor='rgb(0,0,0)', fontFamily='sansSerif'), bindings.style_type(id='SEQ59.defaultStyle1', fontSize='12px', color='rgb(255,255,255)', backgroundColor='rgb(0,0,0)', fontFamily='sansSerif'), bindings.style_type(id='SEQ60.defaultStyle1', fontSize='12px', color='rgb(0,255,255)', backgroundColor='rgb(0,0,0)', fontFamily='sansSerif'), bindings.style_type(id='SEQ61.defaultStyle1', fontSize='12px', color='rgb(255,255,255)', backgroundColor='rgb(0,0,0)', fontFamily='sansSerif')), bindings.layout( bindings.region_type(id='SEQ58.bottomRegion1', origin='14.375% 60%', extent='71.25% 24%', style=['SEQ58.defaultStyle1']), bindings.region_type(id='SEQ59.bottomRegion1', origin='14.375% 60%', extent='71.25% 24%', style=['SEQ58.defaultStyle1']), bindings.region_type(id='SEQ60.bottomRegion1', origin='14.375% 60%', extent='71.25% 24%', style=['SEQ58.defaultStyle1']), bindings.region_type(id='SEQ61.bottomRegion1', origin='14.375% 60%', extent='71.25% 24%', style=['SEQ58.defaultStyle1']))) body_elem = bindings.body_type( bindings.div_type(bindings.p_type( bindings.span_type('Some example text...', style=['SEQ58.defaultStyle1'], id='span1'), bindings.br_type(), bindings.span_type('And another line', style=['SEQ58.defaultStyle1'], id='span2'), id='ID005'), region='SEQ58.bottomRegion1'), bindings.div_type(bindings.p_type( bindings.span_type('Another example text...', style=['SEQ59.defaultStyle1'], id='span3'), bindings.br_type(), bindings.span_type('And another line', style=['SEQ59.defaultStyle1'], id='span4'), id='ID006'), region='SEQ59.bottomRegion1'), bindings.div_type(bindings.p_type( bindings.span_type('More example text...', style=['SEQ60.defaultStyle1'], id='span5'), bindings.br_type(), bindings.span_type('And another line', style=['SEQ60.defaultStyle1'], id='span6'), id='ID007'), region='SEQ60.bottomRegion1'), bindings.div_type(bindings.p_type( bindings.span_type('Further example text...', style=['SEQ61.defaultStyle1'], id='span7'), bindings.br_type(), bindings.span_type('And another line', style=['SEQ61.defaultStyle1'], id='span8'), id='ID008'), region='SEQ61.bottomRegion1'), ) tt.head = head_elem tt.body = body_elem test_old_ids = ({ 'SEQ58.defaultStyle1': 1, 'SEQ59.defaultStyle1': 2, 'SEQ60.defaultStyle1': 3, 'SEQ61.defaultStyle1': 4, 'SEQ58.bottomRegion1': 5, 'SEQ59.bottomRegion1': 6, 'SEQ60.bottomRegion1': 7, 'SEQ61.bottomRegion1': 8 }) test_new_ids = ({ 1: 'SEQ61.defaultStyle1', 3: 'SEQ60.defaultStyle1', 5: 'SEQ61.bottomRegion1' }) replaceStylesAndRegions = deduplicator.ReplaceStylesAndRegions def test_one(self): document = EBUTT3Document.create_from_raw_binding(binding=self.tt) document.validate() cdoc = self.replaceStylesAndRegions(document, self.test_old_ids, self.test_new_ids) cdoc.proceed() document.validate() print document.get_xml()
def test_simple(self): tt = bindings.tt( sequenceIdentifier='testSequence001', sequenceNumber='1', timeBase='clock', extent='800px 600px', clockMode='local', lang='en-GB' ) head_elem = bindings.head_type( metadata.headMetadata_type( metadata.documentMetadata() ), bindings.styling( bindings.style_type( id='style1', fontSize='12px' ), bindings.style_type( id='style2', fontSize='15px' ), bindings.style_type( id='style3', color='red', fontSize='12px' ) ), bindings.layout( bindings.region_type( id='region1', origin='200px 450px', extent='300px 150px', style=['style3'] ) ) ) body_elem = bindings.body_type( bindings.div_type( bindings.p_type( bindings.span_type( 'Some example text...' ), bindings.br_type(), bindings.span_type( 'And another line' ), id='ID005', begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)), end=datatypes.LimitedClockTimingType(timedelta(seconds=3.42)), ), style=['style1'], region='region1' ), begin=datatypes.LimitedClockTimingType(timedelta(seconds=.5)), dur=datatypes.LimitedClockTimingType(timedelta(seconds=5)), style=['style2'] ) tt.head = head_elem tt.body = body_elem document = EBUTT3Document.create_from_raw_binding(binding=tt) document.validate() document.extract_segment(deconflict_ids=True)