def update_children_timing(element, timebase, delay_int): # if the element has a child if hasattr(element, 'orderedContent'): children = element.orderedContent() for child in children: if hasattr(child.value, 'end') and child.value.end != None: if timebase == 'clock': delay = LimitedClockTimingType( timedelta(seconds=delay_int)) child.value.end = LimitedClockTimingType( child.value.end.timedelta + delay.timedelta) elif timebase == 'media': delay = FullClockTimingType(timedelta(seconds=delay_int)) child.value.end = FullClockTimingType( child.value.end.timedelta + delay.timedelta) if hasattr(child.value, 'begin') and child.value.begin != None: if timebase == 'clock': delay = LimitedClockTimingType( timedelta(seconds=delay_int)) child.value.begin = LimitedClockTimingType( child.value.begin.timedelta + delay.timedelta) elif timebase == 'media': delay = FullClockTimingType(timedelta(seconds=delay_int)) child.value.begin = FullClockTimingType( child.value.begin.timedelta + delay.timedelta) else: update_children_timing(child.value, timebase, delay_int)
def update_body_timing(body, timebase, delay_int): if hasattr(body, 'begin'): assert body.begin == None, "The body already has a begin time" # we always update the begin attribute, regardless of the presence of a begin or end attribute if timebase == 'clock': delay = LimitedClockTimingType(timedelta(seconds=delay_int)) body.begin = LimitedClockTimingType(delay.timedelta) elif timebase == 'media': delay = FullClockTimingType(timedelta(seconds=delay_int)) body.begin = FullClockTimingType(delay.timedelta) # if the body has an end attribute, we add to it the value of the delay if hasattr(body, 'end') and body.end != None: if timebase == 'clock': delay = LimitedClockTimingType(timedelta(seconds=delay_int)) body.end = LimitedClockTimingType(body.end.timedelta + delay.timedelta) elif timebase == 'media': delay = FullClockTimingType(timedelta(seconds=delay_int)) body.end = FullClockTimingType(body.end.timedelta + delay.timedelta)
def when_range_requested(template_file, test_context, template_dict, range_from, range_to): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) fragment = document.extract_segment( FullClockTimingType(range_from).timedelta, FullClockTimingType(range_to).timedelta) test_context['fragment'] = fragment
def then_fragment_body_times(test_context, frag_body_begin, frag_body_end): assert test_context[ 'fragment'].binding.body.computed_begin_time == FullClockTimingType( frag_body_begin).timedelta if frag_body_end == 'undefined': assert test_context['fragment'].binding.body.computed_end_time is None else: assert test_context[ 'fragment'].binding.body.computed_end_time == FullClockTimingType( frag_body_end).timedelta
def then_fragment_span3_times(test_context, frag_span3_begin, frag_span3_end): if frag_span3_begin == 'deleted': assert_raises(LookupError, test_context['fragment'].get_element_by_id, 'span3') else: assert test_context['fragment'].get_element_by_id( 'span3').computed_begin_time == FullClockTimingType( frag_span3_begin).timedelta if frag_span3_end == 'undefined': assert test_context['fragment'].get_element_by_id( 'span3').computed_end_time is None else: assert test_context['fragment'].get_element_by_id( 'span3').computed_end_time == FullClockTimingType( frag_span3_end).timedelta
def timestr_to_timedelta(time_str, time_base): if time_base == 'clock': return LimitedClockTimingType(time_str).timedelta elif time_base == 'media': return FullClockTimingType(time_str).timedelta elif time_base == 'smpte': raise NotImplementedError('SMPTE needs implementation')
def then_body_active_begin(test_context, body_active_begin): computed_begin = test_context['document'].binding.body.computed_begin_time if body_active_begin == "undefined": assert computed_begin is None else: body_active_begin_timedelta = FullClockTimingType( body_active_begin).timedelta assert body_active_begin_timedelta == computed_begin
def then_p_active_end(test_context, p_active_end): computed_end = test_context['document'].binding.body.orderedContent( )[0].value.orderedContent()[0].value.computed_end_time if p_active_end == "undefined": assert computed_end is None else: p_active_end_timedelta = FullClockTimingType(p_active_end).timedelta assert p_active_end_timedelta == computed_end
def then_span2_active_begin(test_context, span2_active_begin): computed_begin = test_context['document'].binding.body.orderedContent( )[0].value.orderedContent()[0].value.orderedContent( )[3].value.computed_begin_time if span2_active_begin == "undefined": assert computed_begin is None else: span2_active_begin_timedelta = FullClockTimingType( span2_active_begin).timedelta assert span2_active_begin_timedelta == computed_begin
def when_sequence_segmented(sequence, test_context, range_from, range_to): fragment = sequence.extract_segment( FullClockTimingType(range_from).timedelta, FullClockTimingType(range_to).timedelta) test_context['fragment'] = fragment
def when_doc_available(test_context, availability_time): if availability_time: test_context['document'].availability_time = FullClockTimingType( availability_time).timedelta
def when_document_availability_time(test_context, avail_time_1): test_context['document'].availability_time = FullClockTimingType( avail_time_1).timedelta