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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
# SPDX-FileCopyrightText: All Contributors to the PyTango project
# SPDX-License-Identifier: LGPL-3.0-or-later
import pytest
from tango import (
Attribute,
MultiAttrProp,
DevEncoded,
)
from tango.server import Device
from tango.server import command, attribute
from tango.test_utils import (
DeviceTestContext,
)
class SimpleDevice(Device):
@attribute(dtype=bool)
def attr_bool(self):
pass
@attribute(dtype=str)
def attr_str(self):
pass
@attribute(dtype=DevEncoded)
def attr_enc(self):
pass
def check_multi_attr(self, attr_name):
attr = self.get_device_attr().get_attr_by_name(attr_name)
assert isinstance(attr, Attribute)
prop = attr.get_properties()
assert isinstance(prop, MultiAttrProp)
prop = MultiAttrProp()
ret = attr.get_properties(prop)
assert isinstance(prop, MultiAttrProp)
assert prop is ret
with pytest.raises(
TypeError, match="attr_cfg must be an instance of MultiAttrProp"
):
attr.get_properties([])
assert prop.label == attr_name
assert prop.unit == ""
prop.unit = "kgm^2/s"
attr.set_properties(prop)
with pytest.raises(
TypeError, match="attr_cfg must be an instance of MultiAttrProp"
):
attr.set_properties([])
@command
def check_attr_str(self):
self.check_multi_attr("attr_str")
@command
def check_attr_enc(self):
self.check_multi_attr("attr_enc")
@command
def check_attr_bool(self):
self.check_multi_attr("attr_bool")
def test_stuff():
with DeviceTestContext(SimpleDevice) as proxy:
proxy.check_attr_str()
info = proxy.attribute_query("attr_str")
assert info.unit == "kgm^2/s"
proxy.check_attr_enc()
info = proxy.attribute_query("attr_enc")
assert info.unit == "kgm^2/s"
proxy.check_attr_bool()
info = proxy.attribute_query("attr_bool")
assert info.unit == "kgm^2/s"
|