Device Test Context Classes API¶
The API of the testing classes are described here. For an overview of their behaviour, see Approaches to testing Tango devices.
DeviceTestContext¶
-
class
tango.test_context.
DeviceTestContext
(device, device_cls=None, server_name=None, instance_name=None, device_name=None, properties=None, db=None, host=None, port=0, debug=3, process=False, daemon=False, timeout=None, memorized=None)¶ Bases:
tango.test_context.MultiDeviceTestContext
Context to run a single device without a database.
The difference with respect to
MultiDeviceTestContext
is that it only allows to export a single device.Example usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
from time import sleep from tango.server import Device, attribute, command from tango.test_context import DeviceTestContext class PowerSupply(Device): @attribute(dtype=float) def voltage(self): return 1.23 @command def calibrate(self): sleep(0.1) def test_calibrate(): '''Test device calibration and voltage reading.''' with DeviceTestContext(PowerSupply, process=True) as proxy: proxy.calibrate() assert proxy.voltage == 1.23
- Parameters
-
append_db_file
(server, instance, tangoclass, device_prop_info)¶ Generate a database file corresponding to the given arguments.
-
delete_db
()¶ delete temporary database file only if it was created by this class
-
get_device
(device_name)¶ Return the device proxy corresponding to the given device name.
Maintains previously accessed device proxies in a cache to not recreate then on every access.
-
get_device_access
(device_name=None)¶ Return the full device name.
-
get_server_access
()¶ Return the full server name.
-
start
()¶ Run the server.
-
stop
()¶ Kill the server.
MultiDeviceTestContext¶
-
class
tango.test_context.
MultiDeviceTestContext
(devices_info, server_name=None, instance_name=None, db=None, host=None, port=0, debug=3, process=False, daemon=False, timeout=None)¶ Bases:
object
Context to run device(s) without a database.
The difference with respect to
DeviceTestContext
is that it allows to export multiple devices (even of different Tango classes).Example usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
from tango.server import Device, attribute from tango.test_context import MultiDeviceTestContext class Device1(Device): @attribute def attr1(self): return 1.0 class Device2(Device): @attribute def read_attr2(self): return 2.0 devices_info = ( { "class": Device1, "devices": [ { "name": "test/device1/1" }, ] }, { "class": Device2, "devices": [ { "name": "test/device2/1", }, ] } ) def test_devices(): with MultiDeviceTestContext(devices_info, process=True) as context: proxy1 = context.get_device("test/device1/1") proxy2 = context.get_device("test/device2/1") assert proxy1.attr1 == 1.0 assert proxy2.attr2 == 2.0
- Parameters
devices_info (sequence<dict>) –
a sequence of dicts with information about devices to be exported. Each dict consists of the following keys:
”class” which value is either of:
: class:~tango.server.Device or the name of some such class
a sequence of two elements, the first element being a
DeviceClass
or the name of some such class, the second element being aDeviceImpl
or the name of such such class
”devices” which value is a sequence of dicts with the following keys:
”name” (str)
”properties” (dict)
”memorized” (dict)
server_name (
str
) – Name to use for the device server. Optional. Default is the first device’s class name.instance_name (
str
) – Name to use for the device server instance. Optional. Default is lower-case version of the server name.db (
str
) – Path to a pre-populated text file to use for the database. Optional. Default is to create a new temporary file and populate it based on the devices and properties supplied in devices_info.host (
str
) – Hostname to use for device server’s ORB endpoint. Optional. Default is a local IP address.port (
int
) – Port number to use for the device server’s ORB endpoint. Optional. Default is chosen by omniORB.debug (
int
) – Debug level for the device server logging. 0=OFF, 1=FATAL, 2=ERROR, 3=WARN, 4=INFO, 5=DEBUG. Optional. Default is warn.process (
bool
) – True if the device server should be launched in a new process, otherwise use a new thread. Note: if the context will be used mutiple times, it may seg fault if the thread mode is chosen. Optional. Default is thread.daemon (
bool
) – True if the new thread/process must be created in daemon mode. Optional. Default is not daemon.timeout (
float
) – How long to wait (seconds) for the device server to start up, and also how long to wait on joining the thread/process when stopping. Optional. Default differs for thread and process modes.
-
append_db_file
(server, instance, tangoclass, device_prop_info)¶ Generate a database file corresponding to the given arguments.
-
delete_db
()¶ delete temporary database file only if it was created by this class
-
get_device
(device_name)¶ Return the device proxy corresponding to the given device name.
Maintains previously accessed device proxies in a cache to not recreate then on every access.
-
get_device_access
(device_name)¶ Return the full device name.
-
get_server_access
()¶ Return the full server name.
-
start
()¶ Run the server.
-
stop
()¶ Kill the server.