latest.ipv8.test.messaging.test_payload_dataclass

Module Contents

Classes

NativeBool

A single boolean payload.

NativeInt

A single integer payload.

NativeBytes

A single bytes payload.

NativeStr

A single string payload.

SerializerType

A Serializer format payload.

NestedType

A single nested payload.

NestedListType

A single list of nested payload.

ListIntType

A single list of integers.

ListBoolType

A single list of booleans.

Unknown

To whomever is reading this and wondering why dict is not supported: use a nested payload instead.

A

A payload consisting of two integers.

B

A payload consisting of two integers, of which one has a default value.

FwdDataclass

A payload to test if the dataclass overwrite forwards its arguments to the "real" dataclass.

StripMsgId

Payload to make sure that the message id is not seen as a field.

FwdMsgId

Payload that specfies the message id as an argument to the dataclass overwrite.

EverythingItem

An item for the following Everything payload.

Everything

Dataclass payload that includes all functionality.

TestDataclassPayload

Tests for dataclass-based payloads.

Attributes

varlenH

T

latest.ipv8.test.messaging.test_payload_dataclass.varlenH
latest.ipv8.test.messaging.test_payload_dataclass.T
class latest.ipv8.test.messaging.test_payload_dataclass.NativeBool

A single boolean payload.

a: bool
class latest.ipv8.test.messaging.test_payload_dataclass.NativeInt

A single integer payload.

a: int
class latest.ipv8.test.messaging.test_payload_dataclass.NativeBytes

A single bytes payload.

a: bytes
class latest.ipv8.test.messaging.test_payload_dataclass.NativeStr

A single string payload.

a: str
class latest.ipv8.test.messaging.test_payload_dataclass.SerializerType

A Serializer format payload.

a: varlenH
class latest.ipv8.test.messaging.test_payload_dataclass.NestedType

A single nested payload.

a: NativeInt
class latest.ipv8.test.messaging.test_payload_dataclass.NestedListType

A single list of nested payload.

a: List[NativeInt]
class latest.ipv8.test.messaging.test_payload_dataclass.ListIntType

A single list of integers.

a: List[int]
class latest.ipv8.test.messaging.test_payload_dataclass.ListBoolType

A single list of booleans.

a: List[bool]
class latest.ipv8.test.messaging.test_payload_dataclass.Unknown

To whomever is reading this and wondering why dict is not supported: use a nested payload instead.

a: dict
class latest.ipv8.test.messaging.test_payload_dataclass.A

A payload consisting of two integers.

a: int
b: int
class latest.ipv8.test.messaging.test_payload_dataclass.B

A payload consisting of two integers, of which one has a default value.

a: int
b: int = 3
class latest.ipv8.test.messaging.test_payload_dataclass.FwdDataclass

A payload to test if the dataclass overwrite forwards its arguments to the “real” dataclass.

a: int
class latest.ipv8.test.messaging.test_payload_dataclass.StripMsgId

Payload to make sure that the message id is not seen as a field.

a: int
msg_id = 1
names = []
format_list = []
class latest.ipv8.test.messaging.test_payload_dataclass.FwdMsgId

Payload that specfies the message id as an argument to the dataclass overwrite.

a: int
names = []
format_list = []
class latest.ipv8.test.messaging.test_payload_dataclass.EverythingItem

An item for the following Everything payload.

a: bool
class latest.ipv8.test.messaging.test_payload_dataclass.Everything

Dataclass payload that includes all functionality.

a: int
b: bytes
c: varlenH
d: EverythingItem
e: List[EverythingItem]
f: str
g: List[int]
h: List[bool]
class latest.ipv8.test.messaging.test_payload_dataclass.TestDataclassPayload(methodName: str = 'runTest')

Bases: latest.ipv8.test.base.TestBase

Tests for dataclass-based payloads.

static _pack_and_unpack(payload: type[T], instance: object) T

Serialize and unserialize an instance of payload.

Parameters:
  • payload (type(Payload)) – the payload class to serialize for

  • instance (Payload) – the payload instance to serialize

Returns:

the repacked instance

test_base_unnamed() None

Check if the wrapper returns the payload correctly with unnamed arguments.

test_base_named() None

Check if the wrapper returns the payload correctly with named arguments.

test_pass_default() None

Check if the wrapper forwards default values.

test_pass_default_overwrite() None

Check if the wrapper correctly overwrites default values.

test_nativebool_t_payload() None

Check if unpacked BitPayload(true) works correctly.

test_nativebool_f_payload() None

Check if unpacked BitPayload(false) works correctly.

test_nativeint_negative_payload() None

Check if unpacked NativeInt(-1) works correctly.

test_nativeint_zero_payload() None

Check if unpacked NativeInt(0) works correctly.

test_nativeint_positive_payload() None

Check if unpacked NativeInt(1) works correctly.

test_nativebytes_empty_payload() None

Check if unpacked NativeBytes(b’’) works correctly.

test_nativebytes_filled_payload() None

Check if unpacked NativeBytes(b’hi’) works correctly.

test_nativestr_empty_payload() None

Check if unpacked NativeStr(‘’) works correctly.

test_nativestr_filled_payload() None

Check if unpacked NativeStr(‘hi’) works correctly.

test_serializertype_payload() None

Check if a custom SerializerType (“varlenH”) works correctly.

test_nested_payload() None

Check if a nested payload works correctly.

test_native_intlist_payload() None

Check if a list of native types works correctly.

test_native_boollist_payload() None

Check if a list of native types works correctly.

test_nestedlist_empty_payload() None

Check if an empty list of nested payloads works correctly.

test_nestedlist_filled_payload() None

Check if a list of nested payloads works correctly.

test_unknown_payload() None

Check if an unknown type raises an error.

test_fwd_args() None

Check if dataclass_payload forwards its arguments to dataclass.

We forward eq=False because it’s easy to test.

test_strip_msg_id() None

Check if the msg_id field is identifier and stripped.

test_fwd_msg_id() None

Check if the msg_id argument is sets the Payload msg_id.

test_everything() None

Check if the wrapper handles all of the different data types together.