def test_raw_frame_equality(): empty_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, b'') base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, b'\x01') assert empty_frame == empty_frame assert not (empty_frame == base_frame) assert not (empty_frame == 5) assert not (empty_frame != empty_frame) assert empty_frame != base_frame assert empty_frame != 5
def test_serialize_frame_with_empty_payload(): empty_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, b'') (base, ) = list(_frames.serialize_frame(empty_frame)) assert base[ 0: 16] == b'\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x04\x05\x00' assert base[16:] == b'\x00\x00\x00\x00\x00\x00\x00\x00'
def test_raw_frame_conversion(): base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, b'\x01') assert base_frame == base_frame, "Pre-requisite failed" assert base_frame == types.RawFrame.from_raw(base_frame) assert base_frame == base_frame.to_raw()
def test_serialize_frame_with_base_payload(): payload = b'\x01\x02\x03\x04\x05\x06\x07\x08' base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, payload) (base, ) = list(_frames.serialize_frame(base_frame)) assert base[ 0: 16] == b'\x01\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x04\x05\x08' assert base[16:] == b'\x01\x02\x03\x04\x05\x06\x07\x08'
def test_serialize_frame_with_excessive_payload(): payload = 0xFF * b'\x01\x02\x03\x04\x05\x06\x07\x08' base_frame = types.RawFrame(1, 2, constants.FrameType.CAN_DATA, 4, 5, payload) with pytest.raises(errors.XnetError): list(_frames.serialize_frame(base_frame))