communication.communicators.mock_communicator module

This module contains a mock client and communicator for testing purposes.

class communication.communicators.mock_communicator.MockCommunicator(identifier)[source]

Bases: Communicator[MockConnection]

A mock communicator for testing applications. All the pools must be able to reference each other’s communicators, i.e. be running in the same python process.

__init__(identifier)[source]

Initialise the mock communicator

Parameters:

identifier (str) – the unique identifier of the communicator

__str__()[source]

String representation of Self.

Return type:

str

async process_packet(sender_id, packet)[source]

‘Receive’ a packet from a remote peer.

Parameters:
  • packet (bytes) – the message

  • sender_id (str) – the sender identifier

Return type:

None

class communication.communicators.mock_communicator.MockConnection(remote)[source]

Bases: object

Mock Connection.

Simply keeps a reference to the remote Communicator instance to be able to directly call its receive_handler.

__init__(remote)[source]

Initialise the mock client.

Each client must have a reference to the communicator of that client. E.g. If party A adds party B to its pool, it must provide the communicator of Party B as input.

Parameters:

remote (MockCommunicator) – The communicator of that party.

__str__()[source]

String representation of Self.

Return type:

str