MockChannel#
- class maize.utilities.testing.MockChannel(items: T | list[T] | None = None)[source]#
Bases:
Channel
[T
]Mock channel class presenting a Channel interface for testing. Can be loaded with an item to simulate a node receiving it from a neighbour. Can also be used to retrieve a sent item for assertions.
- Parameters:
items – Items to be loaded into the channel
Methods
__init__
([items])close
()Closes the channel.
flush
([timeout])Flush the contents of the channel.
get
()Unconditionally get the stored item for assertions.
kill
()Kills the channel, called at network shutdown and ensures no orphaned processes.
receive
([timeout])Receive an item.
send
(item[, timeout])Send an item.
Attributes
Returns whether the channel is active.
Returns whether the channel is ready to receive from.
Returns the current approximate size of the buffer
- flush(timeout: float = 0.1) list[T] [source]#
Flush the contents of the channel.
- Parameters:
timeout – The timeout for item retrieval
- Returns:
List of unserialized channel contents
- Return type:
list[T]
- kill() None [source]#
Kills the channel, called at network shutdown and ensures no orphaned processes.
- receive(timeout: float | None = None) T | None [source]#
Receive an item.
- Parameters:
timeout – Timeout in seconds to wait for an item
- Returns:
The received item, or
None
if the channel is empty- Return type:
T | None
- send(item: T, timeout: float | None = None) None [source]#
Send an item.
Will attempt to send an item of any type into a channel, potentially blocking if the channel is full.
- Parameters:
item – Item to send
timeout – Timeout in seconds to wait for space in the channel
- Raises:
ChannelFull – If the channel is already full