From 634e66c88e899facf2e8d09739b6da7d198c75e0 Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Tue, 25 Jan 2022 17:18:31 +0100 Subject: [PATCH] L2SS-480: Mock the DeviceProxy in unit tests, as they do not work in the DeviceTestContext and we avoid using them anyway. --- .../tangostationcontrol/devices/beam.py | 10 +++------- .../test/devices/test_beam_device.py | 7 +++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/devices/beam.py b/tangostationcontrol/tangostationcontrol/devices/beam.py index b27e21c8a..e4a85594a 100644 --- a/tangostationcontrol/tangostationcontrol/devices/beam.py +++ b/tangostationcontrol/tangostationcontrol/devices/beam.py @@ -59,8 +59,6 @@ class Beam(lofar_device): dtype=(numpy.double,), max_dim_x=96, fget=lambda self: self._hbat_pointing_timestamp) - RECV_name = 'stat/recv/1' - # Directory where the casacore measures that we use, reside. We configure ~/.casarc to # use the symlink /opt/IERS/current, which we switch to the actual set of files to use. measures_directory_R = attribute(dtype=str, access=AttrWriteType.READ, fget = lambda self: get_measures_directory()) @@ -73,13 +71,11 @@ class Beam(lofar_device): # -------- @log_exceptions() def configure_for_initialise(self): - # Set a reference of RECV device - try: - self.recv_proxy = DeviceProxy(self.RECV_name) - except: - logger.warning("RECV device offline") # avoid error raising in unittest super().configure_for_initialise() + # Set a reference of RECV device + self.recv_proxy = DeviceProxy("STAT/RECV/1") + # -------- # internal functions # -------- diff --git a/tangostationcontrol/tangostationcontrol/test/devices/test_beam_device.py b/tangostationcontrol/tangostationcontrol/test/devices/test_beam_device.py index 2aa26e1b4..74bdf3eec 100644 --- a/tangostationcontrol/tangostationcontrol/test/devices/test_beam_device.py +++ b/tangostationcontrol/tangostationcontrol/test/devices/test_beam_device.py @@ -31,6 +31,13 @@ class TestBeamDevice(base.TestCase): beam.Beam, 'init_device', spec=beam.Beam.init_device) self.m_init = init_patcher.start() self.addCleanup(init_patcher.stop) + + # Patch DeviceProxy to allow making the proxies during initialisation + # that we otherwise avoid using + proxy_patcher = mock.patch.object( + beam, 'DeviceProxy') + self.m_init = proxy_patcher.start() + self.addCleanup(proxy_patcher.stop) def test_get_pointing_directions(self): """Verify can read pointings attribute and length matches without err""" -- GitLab