def test_bad_parse_code(self): state = bytes_to_state( serialise_to_bytes(bitstream.ParseInfo(parse_code=0x11))) state["_generic_sequence_matcher"] = Matcher(".*") with pytest.raises(decoder.BadParseCode) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_code == 0x11
def test_allowed_zero_next_parse_offset_for_pictures(self, parse_code): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=parse_code, next_parse_offset=0, ))) state["major_version"] = 3 state["_generic_sequence_matcher"] = Matcher(".*") decoder.parse_info(state)
def test_never_allowed_invalid_offset(self, parse_code, next_parse_offset): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=parse_code, next_parse_offset=next_parse_offset, ))) state["_generic_sequence_matcher"] = Matcher(".*") with pytest.raises(decoder.InvalidNextParseOffset) as exc_info: decoder.parse_info(state) assert exc_info.value.next_parse_offset == next_parse_offset
def test_non_zero_previous_parse_offset_for_start_of_sequence(self): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=tables.ParseCodes.end_of_sequence, previous_parse_offset=1, ))) state["_generic_sequence_matcher"] = Matcher(".*") with pytest.raises(decoder.NonZeroPreviousParseOffsetAtStartOfSequence ) as exc_info: decoder.parse_info(state) assert exc_info.value.previous_parse_offset == 1
def test_not_allowed_zero_next_parse_offset_for_non_pictures( self, parse_code): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=parse_code, next_parse_offset=0, ))) state["_generic_sequence_matcher"] = Matcher(".*") with pytest.raises(decoder.MissingNextParseOffset) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_code == parse_code
def test_invalid_generic_sequence(self): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=tables.ParseCodes.end_of_sequence, ))) state["_generic_sequence_matcher"] = Matcher("sequence_header") with pytest.raises(decoder.GenericInvalidSequence) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_code is tables.ParseCodes.end_of_sequence assert exc_info.value.expected_parse_codes == [ tables.ParseCodes.sequence_header ] assert exc_info.value.expected_end is False
def test_level_restricts_sequence(self): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=tables.ParseCodes.end_of_sequence, ))) state["_generic_sequence_matcher"] = Matcher(".*") state["_level_sequence_matcher"] = Matcher("sequence_header") state["level"] = tables.Levels.unconstrained with pytest.raises(decoder.LevelInvalidSequence) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_code is tables.ParseCodes.end_of_sequence assert exc_info.value.expected_parse_codes == [ tables.ParseCodes.sequence_header ] assert exc_info.value.expected_end is False assert exc_info.value.level == tables.Levels.unconstrained
def test_profile_restricts_allowed_parse_codes(self, parse_code, allowed): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=parse_code, next_parse_offset=tables.PARSE_INFO_HEADER_BYTES, ))) state["_generic_sequence_matcher"] = Matcher(".*") state["profile"] = tables.Profiles.high_quality if allowed: decoder.parse_info(state) else: with pytest.raises( decoder.ParseCodeNotAllowedInProfile) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_code == tables.ParseCodes.low_delay_picture assert exc_info.value.profile == tables.Profiles.high_quality
def test_inconsistent_next_parse_offset(self): state = bytes_to_state( serialise_to_bytes( bitstream.ParseInfo( parse_code=tables.ParseCodes.padding_data, next_parse_offset=tables.PARSE_INFO_HEADER_BYTES + 10, )) + b"\x00" * 9 + serialise_to_bytes( bitstream.ParseInfo( parse_code=tables.ParseCodes.end_of_sequence, previous_parse_offset=tables.PARSE_INFO_HEADER_BYTES + 9, ))) state["_generic_sequence_matcher"] = Matcher(".*") decoder.parse_info(state) decoder.read_uint_lit(state, 9) with pytest.raises(decoder.InconsistentNextParseOffset) as exc_info: decoder.parse_info(state) assert exc_info.value.parse_info_offset == 0 assert exc_info.value.next_parse_offset == tables.PARSE_INFO_HEADER_BYTES + 10 assert exc_info.value.true_parse_offset == tables.PARSE_INFO_HEADER_BYTES + 9