From c43bfd6770df1dd2f5bf3aa8623c6beabd37743a Mon Sep 17 00:00:00 2001 From: Jan David Mol <mol@astron.nl> Date: Wed, 13 Oct 2021 17:33:47 +0200 Subject: [PATCH] L2SS-412: Use asynctest for tests (they didnt run without), and fix tests --- devices/test/base.py | 2 +- devices/test/clients/test_opcua_client.py | 6 +++--- devices/test/common/test_lofar_logging.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/devices/test/base.py b/devices/test/base.py index 66e64ea9a..1c2eff09b 100644 --- a/devices/test/base.py +++ b/devices/test/base.py @@ -31,7 +31,7 @@ class TestCase(BaseTestCase): super().setUp() -class AsyncTestCase(BaseTestCase): +class AsyncTestCase(testscenarios.WithScenarios, asynctest.TestCase): """Test case base class for all asyncio unit tests.""" def setUp(self): diff --git a/devices/test/clients/test_opcua_client.py b/devices/test/clients/test_opcua_client.py index 6315abb20..bc13dc5e1 100644 --- a/devices/test/clients/test_opcua_client.py +++ b/devices/test/clients/test_opcua_client.py @@ -70,7 +70,7 @@ class TestOPCua(base.AsyncTestCase): @asynctest.patch.object(OPCUAConnection, "ping") @asynctest.patch.object(opcua_client, "Client") - @mock.patch.object(opcua_client, 'ProtocolAttribute') + @asynctest.patch.object(opcua_client, 'ProtocolAttribute') async def test_opcua_attr_setup(self, m_protocol_attr, m_opc_client, m_ping): """ This tests covers the correct creation of read/write functions. @@ -238,9 +238,9 @@ class TestOPCua(base.AsyncTestCase): # create the protocolattribute if len(j) == 1: - test = opcua_client.ProtocolAttribute(m_node, j[0], 0, opcua_client.numpy_to_OPCua_dict[i.numpy_type], self.loop) + test = opcua_client.ProtocolAttribute(m_node, j[0], 0, opcua_client.numpy_to_OPCua_dict[i.numpy_type]) else: - test = opcua_client.ProtocolAttribute(m_node, j[1], j[0], opcua_client.numpy_to_OPCua_dict[i.numpy_type], self.loop) + test = opcua_client.ProtocolAttribute(m_node, j[1], j[0], opcua_client.numpy_to_OPCua_dict[i.numpy_type]) # comparison function that replaces `set_data_value` inside the attributes write function async def compare_values(val): diff --git a/devices/test/common/test_lofar_logging.py b/devices/test/common/test_lofar_logging.py index 534b2650c..98222563f 100644 --- a/devices/test/common/test_lofar_logging.py +++ b/devices/test/common/test_lofar_logging.py @@ -75,7 +75,7 @@ class TestLofarLogging(base.TestCase): # create a Tango Device that logs something class MyDevice(Device): - def __init__(self): + def init_device(self): self.log_deeper_in_stack() def log_deeper_in_stack(self): @@ -83,7 +83,7 @@ class TestLofarLogging(base.TestCase): with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream: # logs in the constructor already - mydevice = MyDevice() + mydevice = MyDevice(None, "MyDeviceName") self.assertEqual(mydevice, self.memory_handler.records[0].tango_device, msg="configure_logging did not detect active Tango device") self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device") -- GitLab