Skip to content
Snippets Groups Projects
Commit 820d2e69 authored by Jan David Mol's avatar Jan David Mol
Browse files

L2SS-594: Use process=True for the DeviceTestContext to avoid crashes, and...

L2SS-594: Use process=True for the DeviceTestContext to avoid crashes, and move test code into the Device to fix the test.
parent e91cb175
No related branches found
No related tags found
1 merge request!259L2SS-594: Use process=True for the DeviceTestContext to avoid crashes
...@@ -74,25 +74,36 @@ class TestLofarLogging(base.TestCase): ...@@ -74,25 +74,36 @@ class TestLofarLogging(base.TestCase):
logger = lofar_logging.configure_logger() logger = lofar_logging.configure_logger()
# alias to distinguish from other "self"s
test_object = self
# Since we spawn a new process for the Device ("process=True" in the DeviceTestContext),
# and the mock doesn't work across processes, we do all of our mocking and checks in
# the device itself. If any Exception is raised, it will be marshalled to the device
# server by Tango and reraised here in the test as a DevFailed exception.
# create a Tango Device that logs something # create a Tango Device that logs something
class MyDevice(Device): class MyDevice(Device):
def init_device(self): def init_device(self):
self.log_deeper_in_stack() with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream:
self.log_deeper_in_stack()
def log_deeper_in_stack(self): # check if we actually routed the log to self.info_stream
logger.info("test") test_object.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device")
with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream: # Lookup our "test" logline among f.e. the debug messages output by Tango
with DeviceTestContext(MyDevice) as mydevice: test_record = [record for record in test_object.memory_handler.records if record.msg == "test log_deeper_in_stack"]
self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device")
# Lookup our "test" logline among f.e. the debug messages output by Tango # Tango uses slightly different class representations of MyDevice, so
test_record = [record for record in self.memory_handler.records if record.msg == "test"] # we can't compare them direclty. Just verify we're talking about the same thing.
test_object.assertEqual(str(self), str(test_record[0].tango_device), msg="configure_logging did not detect active Tango device")
# Tango uses slightly different class representations of MyDevice, so def log_deeper_in_stack(self):
# we can't compare them direclty. Just verify we're talking about the same thing. logger.info("test log_deeper_in_stack")
self.assertEqual(str(mydevice), str(test_record[0].tango_device), msg="configure_logging did not detect active Tango device")
# if init_device fails, an exception will be thrown
with DeviceTestContext(MyDevice, process=True) as mydevice:
pass
def test_log_exceptions(self): def test_log_exceptions(self):
""" Test whether log_exceptions actually logs and reraises exceptions. """ """ Test whether log_exceptions actually logs and reraises exceptions. """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment