def decode_partial_frame(expect): framer = framing.Framer() framer.append_buffer(b'\x06hello\x07wo') expect(framer.decode_frame()) == None framer.append_buffer(b'rld\x93\x00') expect(framer.decode_frame()) == b'hello\x00world'
def decode_frame_crc_recovery(expect): framer = framing.Framer() framer.append_buffer(b'\x06hello\x07wOr!d\x93\x00') framer.append_buffer(b'\x06hello\x07world\x93\x00') with raises(framing.CRCCheckFailure): framer.decode_frame() expect(framer.decode_frame()) == b'hello\x00world'
def decode_clear_buffer(expect): framer = framing.Framer() framer.append_buffer(b'\x00\x06hello\x07world\x93\x00') framer.clear_buffer() expect(framer.decode_frame()) == None
def decode_frame_no_data(expect): framer = framing.Framer() expect(framer.decode_frame()) == None
def decode_frame_crc_failure(expect): framer = framing.Framer() framer.append_buffer(b'\x06hello\x07wOr!d\x93\x00') with raises(framing.CRCCheckFailure): framer.decode_frame()
def decode_frame_no_crc(expect): framer = framing.Framer(crc=CrcSize.NO_CRC) framer.append_buffer(b'\x06hello\x06world\x00') expect(framer.decode_frame()) == b'hello\x00world'
def decode_frame_preceeding_null(expect): framer = framing.Framer() framer.append_buffer(b'\x00\x06hello\x07world\x93\x00') expect(framer.decode_frame()) == b'hello\x00world'
def decode_frame_crc_32(expect): framer = framing.Framer(crc=CrcSize.CRC32) framer.append_buffer(b'\x00\x06hello\nworld\xb3\x14\xe6\n\x00') expect(framer.decode_frame()) == b'hello\x00world'
def encode_frame_zero_lenth(expect): framer = framing.Framer() with raises(framing.EncodeError): framer.encode_frame(b'')
def encode_frame_crc_32(expect): framer = framing.Framer(crc=CrcSize.CRC32) expect(framer.encode_frame( b'hello\x00world')) == b'\x00\x06hello\nworld\xb3\x14\xe6\n\x00'
def encode_frame_no_crc(expect): framer = framing.Framer(crc=CrcSize.NO_CRC) expect(framer.encode_frame( b'hello\x00world')) == b'\x00\x06hello\x06world\x00'
def encode_frame(expect): framer = framing.Framer() expect(framer.encode_frame( b'hello\x00world')) == b'\x00\x06hello\x07world\x93\x00'