From 07d420cba9e42f0ea007e6b4140c23b09df7486f Mon Sep 17 00:00:00 2001 From: lukken <lukken@astron.nl> Date: Tue, 21 Dec 2021 13:59:10 +0000 Subject: [PATCH] L2SS-456: Integration test check missing opcua attributes --- .../tangostationcontrol/devices/abstract_device.py | 11 ++++++++--- .../tangostationcontrol/devices/sdp/statistics.py | 6 ++++-- .../integration_test/devices/base.py | 7 +++++++ .../test/devices/test_abstract_device.py | 5 +++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/tangostationcontrol/tangostationcontrol/devices/abstract_device.py b/tangostationcontrol/tangostationcontrol/devices/abstract_device.py index 8250e4e48..32b82052d 100644 --- a/tangostationcontrol/tangostationcontrol/devices/abstract_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/abstract_device.py @@ -19,10 +19,15 @@ from tango.server import DeviceMeta logger = logging.getLogger() -class AbstractDeviceMetas(DeviceMeta, ABCMeta): +# TODO(Corne): Fix combining metaclasses by iterating over their variables and +# methods. https://support.astron.nl/jira/browse/L2SS-551 +# class AbstractDeviceMetas(DeviceMeta, ABCMeta): +class AbstractDeviceMetas(DeviceMeta): """Collects meta classes to allow lofar_device to be both a Device and an ABC. """ def __new__(mcs, name, bases, namespace, **kwargs): - cls = ABCMeta.__new__(mcs, name, bases, namespace, **kwargs) - cls = DeviceMeta.__new__(type(cls), name, bases, namespace) + cls = DeviceMeta.__new__(mcs, name, bases, namespace, **kwargs) + # temp_cls = ABCMeta.__new__(mcs, name, bases, namespace) + # setattr(cls, '__abstractmethods__', temp_cls.__abstractmethods__) + # setattr(cls, '_abc_impl', temp_cls._abc_impl) return cls diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py index 4b03f2db7..3bf6d8cc4 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics.py @@ -11,7 +11,7 @@ """ -from abc import ABCMeta, abstractmethod +from abc import abstractmethod # PyTango imports from tango.server import device_property, attribute @@ -33,7 +33,9 @@ import numpy __all__ = ["Statistics"] -class Statistics(opcua_device, metaclass=ABCMeta): +# TODO(Corne): Make Statistics use ABCMeta again when L2SS-551 is fixed +# https://support.astron.nl/jira/browse/L2SS-551 +class Statistics(opcua_device): # In derived classes, set this to a subclass of StatisticsCollector @property diff --git a/tangostationcontrol/tangostationcontrol/integration_test/devices/base.py b/tangostationcontrol/tangostationcontrol/integration_test/devices/base.py index ef4854a82..b66844a18 100644 --- a/tangostationcontrol/tangostationcontrol/integration_test/devices/base.py +++ b/tangostationcontrol/tangostationcontrol/integration_test/devices/base.py @@ -12,6 +12,7 @@ import unittest from tango._tango import DevState +from tangostationcontrol.devices.opcua_device import opcua_device from tangostationcontrol.integration_test.device_proxy import TestDeviceProxy from tangostationcontrol.integration_test import base @@ -55,6 +56,12 @@ class AbstractTestBases: self.assertEqual(DevState.STANDBY, self.proxy.state()) + def test_device_missing_attributes(self): + """Test if any attributes are missing from opcua devices""" + + if isinstance(self.proxy, opcua_device): + self.assertEqual(len(self.proxy.opcua_missing_attributes_R), 0) + def test_device_on(self): """Test if we can transition to on""" diff --git a/tangostationcontrol/tangostationcontrol/test/devices/test_abstract_device.py b/tangostationcontrol/tangostationcontrol/test/devices/test_abstract_device.py index 469ea19fa..badfadade 100644 --- a/tangostationcontrol/tangostationcontrol/test/devices/test_abstract_device.py +++ b/tangostationcontrol/tangostationcontrol/test/devices/test_abstract_device.py @@ -86,4 +86,9 @@ class TestAbstractDevice(base.TestCase): # the expected error. self.assertRaises(TypeError, self.AbstractExample) + @mock.patch.object(server, 'get_worker') + @mock.patch.object(server, 'LatestDeviceImpl') + def test_isinstance(self, m_worker, m_implement): + m_device = self.TestHardwareDevice(mock.Mock(), mock.Mock()) + self.assertFalse(isinstance(m_device, AbstractDeviceMetas)) -- GitLab