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

Hotpatch for logger - use DeviceContext to spawn a test device

parent 1be0203e
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ from common import lofar_logging
import logging
from tango.server import Device
from tango import device_server
from tango.test_context import DeviceTestContext
from test import base
......@@ -82,11 +83,15 @@ class TestLofarLogging(base.TestCase):
logger.info("test")
with mock.patch.object(device_server.DeviceImpl, '__info_stream') as m_info_stream:
# logs in the constructor already
mydevice = MyDevice(None, "MyDeviceName")
with DeviceTestContext(MyDevice) as mydevice:
self.assertEqual(1, m_info_stream.call_count, msg="configure_logger did not send logs to active Tango device")
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")
# Lookup our "test" logline among f.e. the debug messages output by Tango
test_record = [record for record in self.memory_handler.records if record.msg == "test"]
# Tango uses slightly different class representations of MyDevice, so
# we can't compare them direclty. Just verify we're talking about the same thing.
self.assertEqual(str(mydevice), str(test_record[0].tango_device), msg="configure_logging did not detect active Tango device")
def test_log_exceptions(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment