Tango harness

This module implements a test harness for Tango devices.

class BaseTangoHarness(device_info, logger, *args, **kwargs)

A basic test harness for Tango devices.

This harness doesn’t stand up any device; it assumes that devices are already running. It is thus useful for testing against deployed devices.

__init__(device_info, logger, *args, **kwargs)

Initialise a new instance.

Parameters:
  • device_info (Optional[SatDeviceInfo]) – object that makes device info available

  • logger (Logger) – a logger for the harness

  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

property connection_factory: Callable[[str], tango.DeviceProxy]

Establish connections to devices with this factory.

This class uses tango.DeviceProxy as its connection factory.

Returns:

a DeviceProxy for use in establishing connections.

property fqdns: list[str]

Return the FQDNs of devices in this harness.

Returns:

a list of FQDNs of devices in this harness.

get_device(fqdn)

Create and return a proxy to the device at the given FQDN.

Parameters:

fqdn (str) – FQDN of the device for which a proxy is required

Return type:

SatDeviceProxy

Returns:

A proxy of the type specified by the proxy map.

class ClientProxyTangoHarness(device_info, logger, *args, **kwargs)

A test harness for Tango devices that can return tailored client proxies.

__init__(device_info, logger, *args, **kwargs)

Initialise a new instance.

Parameters:
  • device_info (Optional[SatDeviceInfo]) – object that makes device info available

  • logger (Logger) – a logger for the harness

  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

get_device(fqdn)

Create and return a proxy to the device at the given FQDN.

Parameters:

fqdn (str) – FQDN of the device for which a proxy is required

Return type:

SatDeviceProxy

Returns:

A proxy of the type specified by the proxy map.

class DeviceSpecType
class MdtcInfoType
class MockingTangoHarness(harness, mock_factory, initial_mocks, *args, **kwargs)

A Tango test harness that mocks out devices not under test.

This harness wraps another harness, but only uses that harness for a specified set of devices under test, and mocks out all others.

__init__(harness, mock_factory, initial_mocks, *args, **kwargs)

Initialise a new instance.

Parameters:
  • harness (TangoHarness) – the wrapped harness

  • mock_factory (Callable[[], Mock]) – the factory to be used to build mocks

  • initial_mocks (dict[str, Mock]) – a pre-build dictionary of mocks to be used for particular

  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

property connection_factory: Callable[[str], tango.DeviceProxy]

Establish connections to devices with this factory.

This is where we check whether the requested device is on our list. Devices on the list are passed to the connection factory of the wrapped harness. Devices not on the list are intercepted and given a mock factory instead.

Returns:

a factory that putatively provides device connections, but might actually provide mocks.

class SatDeviceInfo(path, package, devices=None)

Data structure class that loads and holds information about devices.

It can provide that information in the format required by tango.test_context.MultiDeviceTestContext.

__init__(path, package, devices=None)

Create a new instance.

Parameters:
  • path (str) – the path to the configuration file that contains information about all available devices.

  • package (str) – name of the package from which to draw classes

  • devices (Optional[list[DeviceSpecType]]) – option specification of devices. If not provided, then devices can be added via the include_device method.

as_mdtc_device_info()

Return this device info in a format required by MultiDeviceTestContext.

Return type:

list[MdtcInfoType]

Returns:

device info in a format required by tango.test_context.MultiDeviceTestContext.

property fqdn_map: dict[str, str]

Return a dictionary that maps device names onto FQDNs.

Returns:

a mapping from device names to FQDNs

property fqdns: Iterable[str]

Return a list of device fqdns.

Returns:

a list of device FQDNs

get_memorized_attributes(name)

Return a map of memorized attributes for a device.

Parameters:

name (str) – name of device

Return type:

dict[str, list[str]]

Returns:

a map of the device’s memorized attributes

include_device(name, proxy, patch=None)

Include a device in this specification.

Parameters:
  • name (str) – the name of the device to be included. The source data must contain configuration information for a device listed under this name

  • proxy (type[SatDeviceProxy]) – the proxy class to use to access the device.

  • patch (Optional[Type[SKABaseDevice]]) – an optional device class with which to patch the named device

Raises:

ValueError – if the named device does not exist in the source configuration data

Return type:

None

property proxy_map: dict[str, Type[ska_sat_lmc.device_proxy.SatDeviceProxy]]

Return a map from FQDN to proxy type.

Returns:

a map from FQDN to proxy type

class StartingStateTangoHarness(harness, *args, bypass_cache=True, check_ready=True, set_test_mode=True, **kwargs)

A test harness for testing Tango devices.

It provides for certain actions and checks that ensure that devices are in a desired initial state prior to testing.

Specifically, it can:

  • Tell devices to bypass their attribute cache, so that written values can be read back immediately

  • Check that devices have completed initialisation and transitioned out of the INIT state

  • Set device testMode to TestMode.TEST

__init__(harness, *args, bypass_cache=True, check_ready=True, set_test_mode=True, **kwargs)

Initialise a new instance.

Parameters:
  • harness (TangoHarness) – the wrapped harness

  • bypass_cache (bool) – whether to tell each device to bypass its attribute cache so that written attribute values can be read back again immediately

  • check_ready (bool) – whether to check whether each device has completed initialisation and transitioned out of INIT state before allowing tests to be run.

  • set_test_mode (bool) – whether to set the device into test mode before allowing tests to be run.

  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

class TangoHarness(*args, **kwargs)

Abstract base class for Tango test harnesses.

This does very little, because it needs to support both harnesses that directly interact with Tango, and wrapper harnesses that add functionality to another harness.

The one really important thing it does do, is ensure that ska_sat_lmc.device_proxy.SatDeviceProxy uses this harness’s connection factory to make connections.

__init__(*args, **kwargs)

Initialise a new instance.

Parameters:
  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

property connection_factory: Callable[[str], tango.DeviceProxy]

Establish connections to devices with this factory.

Raises:

NotImplementedError – because this method is abstract

property fqdns: list[str]

Return FQDNs of devices in this harness.

Raises:

NotImplementedError – because this method is abstract

get_device(fqdn)

Create and return a proxy to the device at the given FQDN.

Parameters:

fqdn (str) – FQDN of the device for which a proxy is required

Raises:

NotImplementedError – because this method is abstract

Return type:

SatDeviceProxy

class TestContextTangoHarness(device_info, logger, *args, process=False, **kwargs)

A test harness for testing MCCS Tango devices in a lightweight test context.

It stands up a tango.test_context.MultiDeviceTestContext with the specified devices.

__init__(device_info, logger, *args, process=False, **kwargs)

Initialise a new instance.

Parameters:
  • device_info (Optional[SatDeviceInfo]) – object that makes device info available

  • logger (Logger) – a logger for the harness

  • process (bool) – whether to run the test context in a separate process or not

  • args (Any) – additional positional arguments

  • kwargs (Any) – additional keyword arguments

property connection_factory: Callable[[str], tango.DeviceProxy]

Establish connections to devices with this factory.

This class uses tango.DeviceProxy but patches it to use the long-form FQDN, as a workaround to an issue with tango.test_context.MultiDeviceTestContext. For more information see https://gitlab.com/tango-controls/pytango/-/issues/459.

Returns:

a DeviceProxy for use in establishing connections.