MockDeviceBuilder Class
- class ska_mid_cbf_mcs.testing.mock.mock_device.MockDeviceBuilder(from_factory: type[~unittest.mock.Mock] = <class 'unittest.mock.Mock'>)[source]
Bases:
objectThis module implements a mock builder for tango devices.
- add_attribute(name: str, value: Any) None[source]
Tell this builder to build mocks with a given attribute.
TODO: distinguish between read-only and read-write attributes
- Parameters:
name – name of the attribute
value – the value of the attribute
- add_property(name: str, value: Any) None[source]
Tell this builder to build mocks with a given device property.
- Parameters:
name – name of the device property
value – the value of the device property
- add_command(name: str, return_value: Any) None[source]
Tell this builder to build mocks with a specified command that returns the provided value.
- Parameters:
name – name of the command
return_value – what the command should return
- add_result_command(name: str, result_code: ResultCode, message: str = 'Mock information-only message') None[source]
Tell this builder to build mocks with a specified command that returns (ResultCode, [message, message_uid]) or (ResultCode, message) tuples as required.
- Parameters:
name – the name of the command
result_code – the
ska_tango_base.commands.ResultCodethat the command should returnmessage – an information-only message for the command to return
- set_state(state: DevState) None[source]
Tell this builder to build mocks with the state set as specified.
- Parameters:
state – the state of the mock
- add_lrc(name: str, queued: bool, result_code: ResultCode | None = None, message: str | None = None, attr_values: Dict[str, Any] | None = None, sleep_time_s: int = 0) None[source]
Tell this builder to build mocks with a specified long-running command that returns ([ResultCode], [command_id]).
The result_code and message parameters are necessary to push an expected change to the longRunningCommandResult attribute, while attr_values can be used to supply further attribute change events that might be expected during the mocked LRC. As a helpful standard, attr_values can at baseline be a dictionary with an empty or None value for longRunningCommandResult, e.g.
::
builder = MockDeviceBuilder() builder.add_lrc( name='On', result_code=ResultCode.OK, message='On completed OK', queued=True, attr_values={ 'longRunningCommandResult': { 'value': ('', ''), 'event': True, } }, )
‘’’
- param name:
the name of the command
- param queued:
if True, return ResultCode.QUEUED, if False, return ResultCode.REJECTED
- param result_code:
the
ska_tango_base.commands.ResultCodethat the command should return- param message:
an information-only message for the command to return
- param attr_values:
dict containing list of attributes and values to push events for in a given LRC
- param sleep_time_s:
sleep time in seconds to wait before pushing change event