ska_pst.testutils.tango

Submodule for Tango related code.

class ska_pst.testutils.tango.AttributesMonitor(device_proxy: PstDeviceProxy, attribute_names: List[str])[source]

Class used to monitor the attributes of a Tango device.

This class can be used to track multiple attributes of a Tango class and then be used to assert values or wait for when an attribute is updated.

Creating the instance of this class does nothing. The setup method must be called afterwards to ensure that attributes are monitored.

assert_attribute(attribute: str, value_assertion: Callable[[...], bool]) None[source]

Assert and attribute has a given value.

This is a helper method to get the attribute’s history and then passes it to the value_assertion callable.

Parameters
  • attribute – the name of the attribute to assert against.

  • value_assertion – a callable to assert against the latest value of the attribute.

assert_attribute_values_changed() None[source]

Assert that attribute values have changed since last check.

assert_attribute_values_not_changed() None[source]

Assert that attribute values have not changed since last check.

capture_current_values() None[source]

Capture the current values to allow for asserting of updates later.

property current_attribute_values: dict

Get current attribute values for device.

get_attribute_history_events(attribute_name: str) List[AttributeHistoryEvent][source]

Get list of history events for an attribute.

setup() None[source]

Set up monitoring for attributes.

teardown() None[source]

Teardown the monitor.

This will unsubscribe from Tango events of the attributes.

wait_for_attribute_update(attribute_name: str, timeout: float) None[source]

Wait for attribute to be updated.

Waits until there has been an update for the specific attribute or a timeout has occured.

Parameters
  • attribute_name – the attribet to wait for an update of.

  • timeout – how long to wait for an update before raising an exception.

class ska_pst.testutils.tango.CommandTracker(device_proxy: PstDeviceProxy, change_event_callbacks: ska_tango_testing.mock.tango.MockTangoEventCallbackGroup, logger: Optional[Logger] = None, default_timeout: float = 5.0)[source]

Class to track the progress and results of commands on a PstDeviceProxy.

This class also uses the TangoDeviceCommandChecker which is more low level to check for updates of the long running process values. This provides a high level view of a command. It also will record if the commands fail and what was the state of the device proxy before the command was executed.

assert_previous_command_error_message_matches(expected_message_regexp: str) None[source]

Assert previous command error message is equal to the argument.

assert_previous_command_failed() None[source]

Assert previous command failed.

assert_previous_command_rejected() None[source]

Assert previous command was rejected due to invalid state.

perform_command(command: str, raise_exception: bool = False, timeout: Optional[float] = None, **kwargs: Any) None[source]

Execute the command.

This method can also optionally reraise the exception during the call rather than storing the exception. This should be used during the setup and teardown of the system.

teardown() None[source]

Teardown the command tracker.

This releases all of the subscriptions and change events used by the tracker.

class ska_pst.testutils.tango.LongRunningCommandTracker(device: tango.DeviceProxy, logger: Optional[Logger] = None)[source]

A convinence class used to help check a Tango Device command.

This class can be used to check that a command executed on a DeviceProxy fires the correct change events for task status, the completion state, and any changes through the ObsState.

assert_command_status_events(command_id: str, expected_command_status_events: List[ska_tango_base.executor.TaskStatus] = [ska_tango_base.executor.TaskStatus.QUEUED, ska_tango_base.executor.TaskStatus.IN_PROGRESS, ska_tango_base.executor.TaskStatus.COMPLETED]) None[source]

Assert that the command has the correct status events.

Parameters
  • command_id – the id of the command to assert events against.

  • expected_command_status_events – a list of expected status events of the command, these should be in the order the events happen. Default expected events are: [TaskStatus.QUEUED, TaskStatus.IN_PROGRESS, TaskStatus.COMPLETED]

wait_for_command_to_complete(command_id: str, timeout: float = 5.0) ska_tango_base.executor.TaskStatus[source]

Wait for a command to complete.

This waits for the a given command to complete within a given timeout. A command is considered complete if the last status event is either: TaskStatus.COMPLETED, TaskStatus.ABORTED, TaskStatus.FAILED, or TaskStatus.REJECTED.

Parameters

command_id – the id of the command to assert events against.

Returns

the task status when the command completes.

Raises

RuntimeError if there is a timeout.

class ska_pst.testutils.tango.PstTestDeviceProxy(fqdn: str, logger: Optional[Logger] = None, command_timeout: float = 30.0)[source]

A class for use when testing a PST Tango Device.

This class is designed as a lightweight proxy that wraps a tango.DeviceProxy. This allows for automated testing or using in a notebook to block on the command calls rather than assuming the calls have finished.

All the commands exposed on this class do not check the current state of the remote device. The remote device is in control of checking state and rejecting methods that are or are not allowed.

Abort() None[source]

Call Abort on remote device.

ConfigureScan(scan_configuration: str) None[source]

Call ConfigureScan on remote device.

This method takes a scan configuration that is passed to the device proxy.

Parameters

scan_configuration – a JSON string of the scan configuration to be sent to the remote device.

EndScan() None[source]

Call EndScan on remote device.

GoToFault(fault_msg: str) None[source]

Call GoToFault on remote device.

GoToIdle() None[source]

Call GoToIdle on remote device.

ObsReset() None[source]

Call ObsReset on remote device.

Off() None[source]

Call Off command on remote device.

On() None[source]

Call On command on remote device.

Scan(scan_id: str) None[source]

Call Scan on remote device.

This will put the remote device in to a SCANNING state.

display_monitoring() None[source]

Display current values of some monitored attributes on remote device.

get_property(propname: str) Any[source]

Get the value of a device property.

This just proxies through to the tango.DeviceProxy.get_property

monitor() None[source]

Start background monitoring of values of remote device.

This method will start a background process to log out the current monitored values. This is done at a rate given by the monitoring polling rate on the remote device.

state() tango.AdminMode[source]

Get the current admin mode state of the remote device.

class ska_pst.testutils.tango.TangoChangeEventHelper(device_under_test: tango.DeviceProxy, change_event_callbacks: ska_tango_testing.mock.tango.MockTangoEventCallbackGroup, logger: Optional[Logger] = None)[source]

Internal testing class used for handling change events.

release() None[source]

Release any subscriptions that are held.

subscribe(attribute_name: str) None[source]

Subscribe to change events of an attribute.

This returns a MockChangeEventCallback that can then be used to verify changes.

class ska_pst.testutils.tango.TangoDeviceCommandChecker(tango_change_event_helper: TangoChangeEventHelper, change_event_callbacks: ska_tango_testing.mock.tango.MockTangoEventCallbackGroup, logger: Optional[Logger] = None)[source]

A convinence class used to help check a Tango Device command.

This class can be used to check that a command executed on a DeviceProxy fires the correct change events for task status, the completion state, and any changes through the ObsState.

assert_command(command: Callable[[], Tuple[List[ska_tango_base.commands.ResultCode], List[str]]], expected_result_code: ska_tango_base.commands.ResultCode = ska_tango_base.commands.ResultCode.QUEUED, expected_command_result: Optional[str] = '"Completed"', expected_command_status_events: List[ska_tango_base.executor.TaskStatus] = [ska_tango_base.executor.TaskStatus.QUEUED, ska_tango_base.executor.TaskStatus.IN_PROGRESS, ska_tango_base.executor.TaskStatus.COMPLETED], expected_obs_state_events: List[ska_control_model.ObsState] = [], timeout: float = 5.0, **kwargs: Any) None[source]

Assert that the command has the correct result and events.

This method has sensible defaults of the expected result code, the overall result, and the status events that the command goes through, and by default asserts that the ObsState model doesn’t change.

Parameters
  • command – a callable on the device proxy.

  • expected_result_code – the expected result code returned from the call. The default is ResultCode.QUEUED.

  • expected_command_result – the expected command result when the command completes. The default is “Completed”.

  • expected_command_status_events – a list of expected status events of the command, these should be in the order the events happen. Default expected events are: [TaskStatus.QUEUED, TaskStatus.IN_PROGRESS, TaskStatus.COMPLETED]

  • expected_obs_state_events – the expected events of the ObsState model. The default is an empty list, meaning no events expected.

  • timeout – expected length of time for the results of the command to take.