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 availablelogger (
Logger
) – a logger for the harnessargs (
Any
) – additional positional argumentskwargs (
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.
- 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 availablelogger (
Logger
) – a logger for the harnessargs (
Any
) – additional positional argumentskwargs (
Any
) – additional keyword arguments
- 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:
- 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 classesdevices (
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:
- 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
- get_memorized_attributes(name)
Return a map of memorized attributes for a device.
- 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 nameproxy (
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:
- 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 harnessbypass_cache (
bool
) – whether to tell each device to bypass its attribute cache so that written attribute values can be read back again immediatelycheck_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 argumentskwargs (
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’sconnection factory
to make connections.- __init__(*args, **kwargs)
Initialise a new instance.
- 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:
- 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:
- 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 withtango.test_context.MultiDeviceTestContext
. For more information see https://gitlab.com/tango-controls/pytango/-/issues/459.- Returns:
a DeviceProxy for use in establishing connections.