Skip to content
Snippets Groups Projects
Commit 811d882e authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-909: Added tests for writing smaller than max spectra/image attributes

parent e8afb0c2
No related branches found
No related tags found
1 merge request!399L2SS-909: Do not allow writes of smaller arrays
...@@ -39,7 +39,6 @@ def dev_init(device): ...@@ -39,7 +39,6 @@ def dev_init(device):
asyncio.run(i.async_set_comm_client(device, device.test_client)) asyncio.run(i.async_set_comm_client(device, device.test_client))
device.test_client.start() device.test_client.start()
class TestAttributeTypes(base.TestCase): class TestAttributeTypes(base.TestCase):
def setUp(self): def setUp(self):
# Avoid the device trying to access itself as a client # Avoid the device trying to access itself as a client
...@@ -491,7 +490,6 @@ class TestAttributeTypes(base.TestCase): ...@@ -491,7 +490,6 @@ class TestAttributeTypes(base.TestCase):
info = "Test failure in {} {} readback test \n\tW: {} \n\tRW: {} \n\tR: {}".format(test_type, dtype, val, result_RW, result_R) info = "Test failure in {} {} readback test \n\tW: {} \n\tRW: {} \n\tR: {}".format(test_type, dtype, val, result_RW, result_R)
raise Exception(info) from e raise Exception(info) from e
""" """
List of different types to be used with attributes testing, using any other List of different types to be used with attributes testing, using any other
might have unexpected results. Each type is bound to a device scalar, might have unexpected results. Each type is bound to a device scalar,
...@@ -629,6 +627,9 @@ class TestAttributeAccess(base.TestCase): ...@@ -629,6 +627,9 @@ class TestAttributeAccess(base.TestCase):
scalar_R = attribute_wrapper(comms_annotation="float32_scalar_R", datatype=numpy.float32) scalar_R = attribute_wrapper(comms_annotation="float32_scalar_R", datatype=numpy.float32)
scalar_RW = attribute_wrapper(comms_annotation="float32_scalar_RW", datatype=numpy.float32, access=AttrWriteType.READ_WRITE) scalar_RW = attribute_wrapper(comms_annotation="float32_scalar_RW", datatype=numpy.float32, access=AttrWriteType.READ_WRITE)
spectrum_RW = attribute_wrapper(comms_annotation="spectrum_RW", dims=(3,), datatype=numpy.float32, access=AttrWriteType.READ_WRITE)
image_RW = attribute_wrapper(comms_annotation="image_RW", dims=(3,2), datatype=numpy.float32, access=AttrWriteType.READ_WRITE)
def configure_for_initialise(self): def configure_for_initialise(self):
dev_init(self) dev_init(self)
self.set_state(DevState.STANDBY) self.set_state(DevState.STANDBY)
...@@ -643,3 +644,30 @@ class TestAttributeAccess(base.TestCase): ...@@ -643,3 +644,30 @@ class TestAttributeAccess(base.TestCase):
proxy.initialise() proxy.initialise()
_ = proxy.scalar_R _ = proxy.scalar_R
def test_write_correct_dims_spectrum(self):
with DeviceTestContext(self.float32_scalar_device, process=True) as proxy:
proxy.initialise()
proxy.spectrum_RW = [1.0, 2.0, 3.0]
def test_write_wrong_dims_spectrum(self):
with DeviceTestContext(self.float32_scalar_device, process=True) as proxy:
proxy.initialise()
with self.assertRaises(DevFailed):
proxy.spectrum_RW = [1.0]
def test_write_correct_dims_image(self):
with DeviceTestContext(self.float32_scalar_device, process=True) as proxy:
proxy.initialise()
proxy.image_RW = [[1.0, 2.0], [2.0, 3.0], [3.0, 4.0]]
def test_write_wrong_dims_image(self):
with DeviceTestContext(self.float32_scalar_device, process=True) as proxy:
proxy.initialise()
with self.assertRaises(DevFailed):
proxy.image_RW = [[1.0, 2.0], [2.0, 3.0]]
...@@ -23,6 +23,9 @@ class test_client(CommClient): ...@@ -23,6 +23,9 @@ class test_client(CommClient):
""" """
super().__init__(fault_func, try_interval) super().__init__(fault_func, try_interval)
# holder for the values of all attributes
self.values = {}
# Explicitly connect # Explicitly connect
self.connect() self.connect()
...@@ -69,26 +72,32 @@ class test_client(CommClient): ...@@ -69,26 +72,32 @@ class test_client(CommClient):
return dims, dtype return dims, dtype
def _setup_mapping(self, dims, dtype): def _setup_mapping(self, annotation, dims, dtype):
""" """
takes all gathered data to configure and return the correct read and write functions takes all gathered data to configure and return the correct read and write functions
""" """
# we emulate that values written to annotations ending in _RW show up in their corresponding _R
# point as well
if annotation.endswith("_RW"):
annotation = annotation[:-1]
if dtype == str and dims == (1,): if dtype == str and dims == (1,):
self.value = '' self.values[annotation] = ''
elif dims == (1,): elif dims == (1,):
self.value = dtype(0) self.values[annotation] = dtype(0)
else: else:
self.value = numpy.zeros(dims, dtype) self.values[annotation] = numpy.zeros(dims, dtype)
def read_function(): def read_function():
logger.debug("from read_function, reading {} array of type {}".format(dims, dtype)) logger.debug("from read_function, reading {}: {} array of type {} == {}".format(annotation, dims, dtype, self.values[annotation]))
return self.value return self.values[annotation]
def write_function(write_value): def write_function(write_value):
logger.debug("from write_function, writing {} array of type {}".format(dims, dtype)) logger.debug("from write_function, writing {}: {} array of type {}".format(annotation, dims, dtype))
self.value = write_value self.values[annotation] = write_value
return
logger.debug("created and bound example_client read/write functions to attribute_wrapper object") logger.debug("created and bound example_client read/write functions to attribute_wrapper object")
return read_function, write_function return read_function, write_function
...@@ -106,7 +115,7 @@ class test_client(CommClient): ...@@ -106,7 +115,7 @@ class test_client(CommClient):
dims, dtype = self._setup_value_conversion(attribute) dims, dtype = self._setup_value_conversion(attribute)
# configure and return the read/write functions # configure and return the read/write functions
read_function, write_function = self._setup_mapping(dims, dtype) read_function, write_function = self._setup_mapping(annotation, dims, dtype)
# return the read/write functions # return the read/write functions
return read_function, write_function return read_function, write_function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment