unitelabs.bus.testing.serial_device_mock
Attributes
- Name
Stub
- Type
- Value
= typing.Callable[[bytes], typing.Optional[bytes]]
- Description
Classes
SerialDeviceMock
A device mock implementation that simulates a serial connection.
Methods
__enter__(self) -> None
__exit__(
- self,
- exc_type,
- exc_val,
- exc_tb
Parameters
- Name
self
- Type
- Default
- Description
- Name
exc_type
- Type
- Default
- Description
- Name
exc_val
- Type
- Default
- Description
- Name
exc_tb
- Type
- Default
- Description
open(self) -> None
close(self) -> None
receive(self) -> None
received(self, data : bytes) -> None
Parameters
- Name
self
- Type
- Default
- Description
- Name
data
- Type
- bytes
- Default
- Description
get_response(self, request : bytes) -> typing.Optional[bytes]
Returns the stubbed response for a given request. Responses from stubs at the end of the list have a higher priority and overwrite responses from the stubs at the beginning of the list.
Parameters
- Name
self
- Type
- Default
- Description
- Name
request
- Type
- bytes
- Default
- Description
The request sent to the hardware.
Response
- Type
- typing.Optional[bytes]
- Description
The response corresponding to the received request.
Attributes
- Name
cancel
- Type
- Value
= threading.Event()
- Description
- Name
reader
- Type
- Value
= threading.Thread(target=self.receive, daemon=True)
- Description
- Name
port
- Type
- str
- Value
= None
- Description
- Name
stubs
- Type
- list[Stub]
- Value
= None
- Description
- Name
logger
- Type
- logging.Logger
- Value
= None
- Description
A standard python logger available to debug device mocks.