diff --git a/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py b/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py new file mode 100644 index 0000000000000000000000000000000000000000..46004707ea59c681015b987ce97adb26931a189a --- /dev/null +++ b/tangostationcontrol/tangostationcontrol/test/devices/test_lofar_device.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# +# This file is part of the LOFAR 2.0 Station Software +# +# +# +# Distributed under the terms of the APACHE license. +# See LICENSE.txt for more info. + +from tango.test_context import DeviceTestContext +from tango.server import attribute + +from tangostationcontrol.devices import lofar_device + +import mock + +from tangostationcontrol.test import base + +class TestLofarDevice(base.TestCase): + def setUp(self): + super(TestLofarDevice, self).setUp() + + # Patch DeviceProxy to allow making the proxies during initialisation + # that we otherwise avoid using + for device in [lofar_device]: + proxy_patcher = mock.patch.object( + device, 'DeviceProxy') + proxy_patcher.start() + self.addCleanup(proxy_patcher.stop) + + def test_read_attribute(self): + """ Test whether read_attribute really returns the attribute. """ + + class MyLofarDevice(lofar_device.lofar_device): + @attribute(dtype=float) + def A(self): + return 42.0 + + @attribute(dtype=float) + def read_attribute_A(self): + return self.read_attribute("A") + + @attribute(dtype=(float,), max_dim_x=2) + def B_array(self): + return [42.0, 43.0] + + @attribute(dtype=(float,), max_dim_x=2) + def read_attribute_B_array(self): + return self.read_attribute("B_array") + + with DeviceTestContext(MyLofarDevice, process=True, timeout=10) as proxy: + proxy.initialise() + self.assertEqual(42.0, proxy.read_attribute_A) + self.assertListEqual([42.0, 43.0], proxy.read_attribute_B_array.tolist())