def test_process_two_documents_ignore_second_sequence_id(self): first_sequence = EBUTT3Document( time_base='clock', clock_mode='local', lang='en-GB', sequence_identifier='testSequenceEncoder01', sequence_number='1') second_sequence = EBUTT3Document( time_base='clock', clock_mode='local', lang='en-GB', sequence_identifier='testSequenceEncoder02', sequence_number='1') self.consumer.process_document(document=first_sequence) self.assertIsInstance(self.consumer._sequence, EBUTT3DocumentSequence) self.assertIsInstance(self.consumer.reference_clock, LocalMachineClock) with self.assertRaises(UnexpectedSequenceIdentifierError) as context: self.consumer.process_document(document=second_sequence) self.assertTrue( 'Rejecting new sequence identifier' in context.exception.message)
def _create_test_document(self): doc = EBUTT3Document(time_base='clock', clock_mode='local', lang='en-GB', sequence_identifier='testSequenceEncoder01', sequence_number='1') 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(hours=11, minutes=32, seconds=1)), end=datatypes.LimitedClockTimingType( timedelta(hours=11, minutes=32, seconds=2)), style=['style4'], id='span1'), bindings.br_type(), bindings.span_type('And another line', begin=datatypes.LimitedClockTimingType( timedelta(hours=11, minutes=32, seconds=3)), end=datatypes.LimitedClockTimingType( timedelta(hours=11, minutes=32, seconds=4)), id='span2'), id='ID005', ), style=['style1'], region='region1'), begin=datatypes.LimitedClockTimingType( timedelta(hours=11, minutes=32, seconds=.5)), dur=datatypes.LimitedClockTimingType( timedelta(hours=11, minutes=32, seconds=5)), style=['style2']) doc.binding.head = head_elem doc.binding.body = body_elem doc.binding.extent = '800px 600px' doc.validate() raw_xml = doc.get_xml() doc = EBUTT3Document.create_from_xml(raw_xml) return doc
def test_is_equal_dom(self): xml = "" file_path = os.path.join(os.path.dirname(__file__), 'data', 'document.xml') with open(file_path) as xml_file: xml = xml_file.read() document1 = EBUTT3Document.create_from_xml(xml) document2 = EBUTT3Document.create_from_xml(xml) self.assertTrue(compare_xml(document1.get_xml(), document2.get_xml())) document2 = EBUTT3Document.create_from_xml(xml.replace('500', '3500')) self.assertFalse(compare_xml(document2.get_xml(), document1.get_xml()))
def test_comparison_different_sequences(self): document1 = EBUTT3Document("clock", 1, "testSeq1", "en-GB", "local") document2 = EBUTT3Document("clock", 2, "testSeq2", "en-GB", "local") # assertRaises does not catch the error correctly without the lambda. self.assertRaises(ValueError, lambda: document1 < document2) self.assertRaises(ValueError, lambda: document2 > document1) self.assertRaises(ValueError, lambda: document1 <= document2) self.assertRaises(ValueError, lambda: document2 >= document1) self.assertRaises(ValueError, lambda: document1 == document2) self.assertRaises(ValueError, lambda: document2 == document1) self.assertRaises(ValueError, lambda: document1 != document2) self.assertRaises(ValueError, lambda: document2 != document1)
def test_comparison_same_sequence(self): document1 = EBUTT3Document("clock", 1, "testSeq", "en-GB", "local") document2 = EBUTT3Document("clock", 2, "testSeq", "en-GB", "local") self.assertTrue(document1 < document2) self.assertTrue(document2 > document1) self.assertTrue(document1 == document1) self.assertTrue(document1 <= document2) self.assertTrue(document2 >= document1) self.assertTrue(document1 <= document1) self.assertTrue(document1 >= document1) self.assertTrue(document1 != document2) self.assertTrue(document2 != document1)
def __init__(self, node_id, reference_clock, segment_length, discard, sequence_identifier, consumer_carriage=None, producer_carriage=None, init_document=None, **kwargs): super(ReSequencer, self).__init__(node_id=node_id, consumer_carriage=consumer_carriage, producer_carriage=producer_carriage, reference_clock=reference_clock, **kwargs) self._last_segment_end = reference_clock.get_time() self._segment_length = timedelta(seconds=segment_length) # self._segment_timer = segment_timer self._segment_counter = 1 self._sequence_identifier = sequence_identifier self._discard = discard if init_document is not None: # Create sequence from init document, in order to immediately start document output log.info('Creating document sequence from init document {}'.format( init_document)) with open(init_document, 'r') as xml_file: xml_content = xml_file.read() xml_doc = EBUTT3Document.create_from_xml(xml_content) self.create_sequence_from_document(xml_doc)
def test_valid_authors_group_id(self): doc = EBUTT3Document(sequence_identifier='testSeq', sequence_number=1, time_base='media', lang='en-GB', authors_group_identifier='agIdTest') self.assertEqual(doc.authors_group_identifier, 'agIdTest')
def when_doc3_added_to_seq(doc3_avail_time, template_file, template_dict, sequence, test_context): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) document.availability_time = timestr_to_timedelta( doc3_avail_time, sequence.reference_clock.time_base) sequence.add_document(document) test_context['doc3'] = document
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 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 on_new_data(self, data): document = None try: document = EBUTT3Document.create_from_raw_binding(CreateFromDocument(data)) except: log.exception(ERR_DECODING_XML_FAILED) raise XMLParsingFailed(ERR_DECODING_XML_FAILED) if document: self._node.process_document(document)
def main(): create_loggers() log.info('Let\'s get started') args = parser.parse_args() if args.input_file: with open(args.input_file, 'r') as ifile: document = EBUTT3Document.create_from_xml(ifile.read()) import ipdb ipdb.set_trace()
def on_new_data(self, data): document = None try: document = EBUTT3Document.create_from_raw_binding(CreateFromDocument(data)) except: log.exception(ERR_DECODING_XML_FAILED) raise XMLParsingFailed(ERR_DECODING_XML_FAILED) if document: document.availability_time = self._node.reference_clock.get_time() self._node.process_document(document)
def test_process_document(self): # This is not quite unit... this is integration test doc = EBUTT3Document(time_base='clock', clock_mode='local', lang='en-GB', sequence_identifier='testSequenceEncoder01', sequence_number='1') self.consumer.process_document(document=doc, availability_time=timedelta()) self.assertIsInstance(self.consumer._sequence, EBUTT3DocumentSequence) self.assertIsInstance(self.consumer.reference_clock, LocalMachineClock)
def on_new_data(self, data): document = None availability_time_str, xml_content = data try: document = EBUTT3Document.create_from_raw_binding(CreateFromDocument(xml_content)) except: log.exception(ERR_DECODING_XML_FAILED) raise XMLParsingFailed(ERR_DECODING_XML_FAILED) if document: availability_time = timestr_manifest_to_timedelta(availability_time_str, self._node.reference_clock.time_base) document.availability_time = availability_time self._node.process_document(document)
def test_availability_time(self): now = datetime.now() availability_time = timedelta(hours=now.hour, minutes=now.minute, seconds=now.second, microseconds=now.microsecond) document = EBUTT3Document("clock", 1, "testSeq1", "en-GB", "local") document.availability_time = availability_time self.assertEqual(document.availability_time, availability_time) # Only way to test the raising of an exception in a setter is by using # this syntax and not the "=" syntax, because of the way the "=" # operator works in python self.assertRaises(TypeError, lambda: document.availability_time(1))
def _generate_document(self, sequence_number=1, offset=None): # offset is a timedelta object to help generate the timings if offset is None: offset = timedelta() # template_file = self._j2env.get_template('mem_prof_document.xml') template_file = Template(raw_template) temp_dict = { 'sequence_number': sequence_number, 'body_begin': ebuttdt.FullClockTimingType(offset) } doc = EBUTT3Document.create_from_xml(template_file.render(temp_dict)) # print 'doc id {} created'.format(id(doc)) return doc
def on_new_data(self, data): document = None availability_time_str, xml_content = data try: document = EBUTT3Document.create_from_raw_binding( CreateFromDocument(xml_content)) except: log.exception(ERR_DECODING_XML_FAILED) raise XMLParsingFailed(ERR_DECODING_XML_FAILED) if document: availability_time = timestr_manifest_to_timedelta( availability_time_str, self._node.reference_clock.time_base) document.availability_time = availability_time self._node.process_document(document)
def _generate_document(self, sequence_number=1, offset=None): # offset is a timedelta object to help generate the timings if offset is None: offset = timedelta() # template_file = self._j2env.get_template('mem_prof_document.xml') template_file = Template(raw_template) temp_dict = { 'sequence_number': sequence_number, 'body_begin': ebuttdt.FullClockTimingType(offset) } doc = EBUTT3Document.create_from_xml( template_file.render(temp_dict) ) # print 'doc id {} created'.format(id(doc)) return doc
def convert_data(self, data, availability_time=None, sequence_identifier=None, **kwargs): binding_inst = CreateFromDocument(xml_text=data) if isinstance(binding_inst, tt_type): doc = EBUTT3Document.create_from_raw_binding( binding_inst, availability_time=availability_time) else: # If not an ebutt live document then a message doc = EBUTTAuthorsGroupControlRequest.create_from_raw_binding( binding_inst, availability_time=availability_time) if sequence_identifier is not None and sequence_identifier != doc.sequence_identifier: log.error('Sequence identifier mismatch found: {} != {}'.format( sequence_identifier, doc.sequence_identifier)) raise UnexpectedSequenceIdentifierError() kwargs.update(dict(raw_xml=data)) return doc, kwargs
def when_doc_added_to_sequence(template_file, template_dict, sequence): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) sequence.add_document(document)
def gen_first_document(test_context, template_dict, template_file_one): xml_file_1 = template_file_one.render(template_dict) document1 = EBUTT3Document.create_from_xml(xml_file_1) test_context['document1'] = document1 document1.validate() return document1
def gen_document(template_file, template_dict): # TODO: This is legacy and to be removed when tests are refactored xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) document.validate() return document
def valid_doc(template_file_two, template_dict): xml_file_2 = template_file_two.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file_2) assert isinstance(document, EBUTT3Document)
def gen_document(template_file, template_dict): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) document.validate() return document
def valid_doc(template_file, template_dict): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) assert isinstance(document, EBUTT3Document)
def when_doc_generated(test_context, template_dict, template_file): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) test_context['document'] = document
def when_doc1_added_to_sequence(doc_list, template_file, template_dict): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) doc_list.append(document)
def when_doc2_added_to_seq(doc2_avail_time, template_file, template_dict, sequence, test_context): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) document.availability_time = timestr_to_timedelta(doc2_avail_time, sequence.reference_clock.time_base) sequence.add_document(document) test_context['doc2'] = document
def when_processes_document(distributing_node, test_context, template_file): xml_file = template_file.render() test_context['document'] = xml_file distributing_node.process_document(EBUTT3Document.create_from_xml(xml_file), raw_xml=xml_file)
def invalid_doc(template_file, template_dict): xml_file = template_file.render(template_dict) with pytest.raises(Exception): EBUTT3Document.create_from_xml(xml_file)
def check_correct_parsing(template_file, template_dict, trusted_timedeltas_index): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) assert document._ebutt3_content.body.begin.timedelta == trusted_timedeltas[trusted_timedeltas_index]
def then_adding_doc2_error(doc_list, template_file, template_dict): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) sequence = EBUTT3DocumentSequence.create_from_document(doc_list[0]) with pytest.raises(Exception): sequence.add_document(document)
def gen_second_document(test_context, template_dict, template_file_two): xml_file_2 = template_file_two.render(template_dict) document2 = EBUTT3Document.create_from_xml(xml_file_2) test_context['document2'] = document2 document2.validate() return document2
def then_adding_doc2_success(doc_list, template_file, template_dict): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) sequence = EBUTT3DocumentSequence.create_from_document(doc_list[0]) sequence.add_document(document)
def when_doc_generated(test_context, template_dict, template_file): # This is a more standard-compliant way to do this xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) test_context['document'] = document
def check_correct_parsing(template_file, template_dict, trusted_timedeltas_index): xml_file = template_file.render(template_dict) document = EBUTT3Document.create_from_xml(xml_file) assert document._ebutt3_content.body.begin.timedelta == trusted_timedeltas[ trusted_timedeltas_index]