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 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 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_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 _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_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 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)