unitelabs.bus.testing.device_mock
Attributes
- Name
Stub
- Type
- Value
= typing.Callable[[bytes], typing.Optional[bytes]]
- Description
Classes
DeviceMock
Abstract base class to mock devices (hardware or software components) for testing purposes.
- Bases
- contextlib.AbstractContextManager
Methods
__init__(self, stubs : typing.Optional[list[Stub]]) -> None
Parameters
- Name
self
- Type
- Default
- Description
- Name
stubs
- Type
- typing.Optional[list[Stub]]
- Default
- = None
- Description
An optional list of stub methods that receive the same request as the device and optionally return the corresponding response. Stubs can be modified later on by directly modifying the `mock.stubs` list. Stubs at the end of the list have a higher priority and overwrite responses from the stubs at the beginning of the list.
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
stubs
- Type
- list[Stub]
- Value
= None
- Description
- Name
logger
- Type
- logging.Logger
- Value
= None
- Description
A standard python logger available to debug device mocks.