Commit 774f2e48 authored by Benoit Formet's avatar Benoit Formet
Browse files

taac: implement allow_failure + tests

parent 32ff008a
Pipeline #51379 failed with stages
in 7 minutes and 41 seconds
......@@ -126,10 +126,13 @@ class TangoCounterController(SamplingCounterController):
dev_attrs = self._proxy.read_attributes(attributes_to_read)
# Check error.
for attr in dev_attrs:
for attr, cnt in zip(dev_attrs, counters):
error = attr.get_err_stack()
if error:
raise tango.DevFailed(*error)
if cnt.allow_failure:
raise tango.DevFailed(*error)
else:
attr.value = numpy.nan
attr_values = [dev_attr.value for dev_attr in dev_attrs]
......@@ -233,6 +236,9 @@ class tango_attr_as_counter(SamplingCounter):
else:
self.format_string = self.tango_format
# ALLOW FAILURE
self.__allow_failure = config.get("allow_failure", True)
# INIT
SamplingCounter.__init__(
self,
......@@ -295,6 +301,19 @@ class tango_attr_as_counter(SamplingCounter):
)
return formated_value
@property
def allow_failure(self):
"""
Allow failure during tango attribute read: True or False
- True: PyTango.DevFailed exception will be raised
- False: No exception raised and read will return numpy.nan
"""
return self.__allow_failure
@allow_failure.setter
def allow_failure(self, allow_failure):
self.__allow_failure = allow_failure
@property
def value(self):
"""
......
......@@ -2,7 +2,7 @@
from tango.server import run
from tango.server import Device
from tango.server import attribute, command
from tango import AttrWriteType
from tango import AttrWriteType, AttrQuality
from tango import DevState
"""
......@@ -24,6 +24,7 @@ class Dummy(Device):
powerdensity = attribute(format="%3.2f")
maxpowerdensity = attribute(format="%3.2f")
firstvelocity = attribute(format="%3.2f")
none_attr = attribute(format="%3.2f")
velocity = attribute(
fget="read_velocity", fset="write_velocity", access=AttrWriteType.READ_WRITE
......@@ -72,6 +73,9 @@ class Dummy(Device):
self.vel = 5
self.acc = 125
# set invalid quality to return numpy.nan
self.none_attr.set_quality(AttrQuality.ATTR_INVALID)
# shutter state
self.set_state(DevState.CLOSE)
......@@ -98,6 +102,9 @@ class Dummy(Device):
def read_maxpower(self):
return 0
def read_none_attr(self):
return None
def read_powerdensity(self):
return 0
......
......@@ -7,6 +7,7 @@
mode: MEAN
unit: km
format: "%5.3f"
allow_failure: False
- name: taac_undu_power_0
attr_name: powers
index: 0
......@@ -26,6 +27,8 @@
- name: taac_undu_wrong_attr_name
attr_name: cracoucas
# wrong attr_name.
- name: taac_none_attr
attr_name: none_attr
- class: tango_attr_as_counter
......
......@@ -467,6 +467,7 @@ def test_prepare_once_prepare_many(session):
def test_tango_attr_counter(beacon, dummy_tango_server, session):
_, device = dummy_tango_server
counter = beacon.get("taac_dummy_position")
# `taac_dummy_position` is a tango_attr_as_counter which refers to
......@@ -540,6 +541,22 @@ def test_tango_attr_counter(beacon, dummy_tango_server, session):
with pytest.raises(KeyError):
_ = beacon.get("no_uri_counter")
device.setDisabled(True)
sc = ct(0.01, taac_vel, taac_pos, taac_acc)
pos = sc.get_data()["taac_undu_position"][0]
assert numpy.isnan(pos)
assert taac_pos.allow_failure is False
taac_pos.allow_failure = True
with pytest.raises(tango.DevFailed):
sc = ct(0.01, taac_vel, taac_pos, taac_acc)
taac_nan = beacon.get("taac_none_attr")
sc = ct(0.01, taac_nan)
counter_value = sc.get_data()["taac_none_attr"][0]
assert numpy.isnan(counter_value)
def test_info_counters(beacon, dummy_tango_server):
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment