diff --git a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py index 3df327161d26de6f681d75f20eb3371b7dc6f9f1..7916d59726457dd3e75e7ce2327d94a719af7e96 100644 --- a/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py +++ b/tangostationcontrol/tangostationcontrol/test/clients/test_attr_wrapper.py @@ -308,7 +308,7 @@ class TestAttributeTypes(base.TestCase): if test_type == "scalar": expected = numpy.zeros((1,), dtype=dtype) - val = proxy.scalar_RW + val = proxy.scalar_R elif test_type == "spectrum": expected = numpy.zeros(spectrum_dims, dtype=dtype) val = proxy.spectrum_R @@ -367,7 +367,48 @@ class TestAttributeTypes(base.TestCase): # reading back happens in readback_test print(" Test passed! Managed to write: ".format(val)) - + + def read_RW_test(self, dev, dtype, test_type): + '''Test device''' + expected = None + val = None + + try: + with DeviceTestContext(dev, process=True) as proxy: + + #initialise + proxy.initialise() + proxy.on() + + if test_type == "scalar": + expected = numpy.zeros((1,), dtype=dtype) + val = proxy.scalar_RW + elif test_type == "spectrum": + expected = numpy.zeros(spectrum_dims, dtype=dtype) + val = proxy.spectrum_RW + elif test_type == "image": + expected = numpy.zeros(image_dims, dtype=dtype) + val = numpy.array(proxy.image_RW) #is needed for STR since they act differently + + # cant use all() for 2d arrays so instead compare the dimensions and then flatten to 2d + self.assertEqual(val.shape, expected.shape, " image R array dimensions got mangled. Expected {}, got {}".format(expected.shape, val.shape)) + val.reshape(-1) + else: + self.assertEqual(1,2, " {} is not a valid test_type. please use either scalar, spectrum or image".format(test_type)) + + if test_type != "scalar": + # spectrums and the now flattened images can be compared with .all() + comparison = expected == val + equal_arrays = comparison.all() + self.assertTrue(equal_arrays, " Value could not be handled by the atrribute_wrappers internal RW storer") + else: + comparison = expected == val + self.assertTrue(comparison, " Value could not be handled by the atrribute_wrappers internal RW storer") + + print(" Test passed! Managed to read internal RW value. got: {}".format(val)) + except Exception as e: + info = "Test failure in {} {} read RW test. Expected: {}, got {}".format(test_type, dtype, expected, val) + raise Exception(info) from e def readback_test(self, dev, dtype, test_type): '''Test device'''