latest.ipv8.test.messaging.test_serialization

Module Contents

Classes

Short

Single unsigned short value.

Byte

Single unsigned char value.

Nested

Nest a list of Byte objects.

Raw

Single raw value.

NestedWithRaw

Payload that uses multiple raw values.

TestSerializer

Tests related to the Serializer.

class latest.ipv8.test.messaging.test_serialization.Short(number: int)

Bases: latest.ipv8.messaging.serialization.Serializable

Single unsigned short value.

format_list = ['H']
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(number: int) Short

Create a new Short object from the unpacked value.

class latest.ipv8.test.messaging.test_serialization.Byte(byte: int)

Bases: latest.ipv8.messaging.serialization.Serializable

Single unsigned char value.

format_list = ['B']
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(byte: int) Byte

Create a new Byte object from the unpacked value.

class latest.ipv8.test.messaging.test_serialization.Nested(byte_list: list[Byte])

Bases: latest.ipv8.messaging.serialization.Serializable

Nest a list of Byte objects.

format_list = [None]
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(byte_list: list[Byte]) Nested

Create a new Byte object from the unpacked Byte objects.

class latest.ipv8.test.messaging.test_serialization.Raw(byte_string: bytes)

Bases: latest.ipv8.messaging.serialization.Serializable

Single raw value.

format_list = ['raw']
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(raw_list: list[Raw]) Raw

Create a new Raw object from the unpacked value.

class latest.ipv8.test.messaging.test_serialization.NestedWithRaw(raw_list: list[list[Raw]])

Bases: latest.ipv8.messaging.serialization.Serializable

Payload that uses multiple raw values.

format_list = [None]
to_pack_list() list[tuple]

Serialize to a Serializer pack list.

classmethod from_unpack_list(raw_list: list[list[Raw]]) NestedWithRaw

Create a new NestedWithRaw object from the unpacked Raw objects.

class latest.ipv8.test.messaging.test_serialization.TestSerializer(methodName: str = 'runTest')

Bases: latest.ipv8.test.base.TestBase

Tests related to the Serializer.

setUp() None

Create a serializer.

check_pack_unpack(format_ser: str, format_unser: str, value: Any) None

Pack a value using a given serializer format and unpack using another format.

Asserts that the value remains unchanged.

test_pack_bool_true() None

Check if ‘true’ booleans can be correctly packed and unpacked.

test_pack_bool_false() None

Check if ‘false’ booleans can be correctly packed and unpacked.

test_pack_byte_0() None

Check if a 0 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_1() None

Check if a 1 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_255() None

Check if a 255 (unsigned byte) can be correctly packed and unpacked.

test_pack_byte_256() None

Check if a 256 (unsigned byte) throws a struct.error.

test_unpack_short_truncated() None

Check if 1 byte string cannot be unpacked as a short.

test_pack_list() None

Check if a list of shorts is correctly packed and unpacked.

test_get_formats() None

Check if all reported formats contain valid packers.

test_add_packer() None

Check if we can add a packer on the fly.

test_nested_serializable() None

Check if we can unpack nested serializables.

test_serializable_byte_256() None

Check if pack_serializable of a 256 (unsigned byte) raises a PackError.

test_serializable_short_from_byte() None

Check if a unpack_serializable of a short from a byte raises a PackError.

test_serializable_list() None

Check if we can (un)pack serializables easily.

test_serializable_list_extra_data() None

Check if we throw an error when we have too much data to unpack.

test_nested_payload_list() None

Check if we can unpack a nested serializable.

test_nested_serializable_raw() None

Check if we can unpack multiple nested serializables that end with raw.