Skip to content

Add string support for MultiDeviceTestContext devices_info class field

Drew Devereux requested to merge github/fork/DrewDevereux/develop into develop

This pull request allows for tango.test_context.MultiDeviceTestContext to be invoked with a devices_info dictionary in which the device class entries are class names rather than class objects. That is, instead of

from tango.test_utils import SimpleDevice
devices_info = (
    {
        "class": SimpleDevice,
        "devices": [
            {
                "name": "test/device1/1"
            }
        ]
    },
)

we can write

devices_info = (
    {
        "class": "tango.test_utils.SimpleDevice",
        "devices": [
            {
                "name": "test/device1/1"
            }
        ]
    },
)

This is useful because it renders the devices_info dict serialisable. When integration testing in a complex device ecosystem with many devices and device properties, the devices_info dict might become very large, and we might even want to test several different arrangements of devices or sets of device properties. Without serialisation, such tests could end up containing an awful lot of declarative code. But with serialisation, we can easily store the devices_info dicts in JSON files, and load them by name as required. Our tests will be much cleaner.

The elements of the implementation and testing are:

  • a slight refactor to move some duplicated code into a _device_class_from_field helper function, which is then enhanced to support class names. The actual loading of a class given its name was already implemented in the device function, so we just make use of that.
  • To test, we need some test devices that are specified in another module, so that they can be imported by name. Tango already provided a SimpleDevice in the tango.test_utils module, so we use it. To allow for testing against devices that use the classic API, the ClassicAPIDeviceImpl and ClassicAPIDeviceClass classes are moved from the local test module into the tango.test_utils module.
  • The new functionality is tested in a new test_multi_devices_info test.

Merge request reports