Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _assert_logfile_messages(self, stdout_messages, logfile):
"""
Verify that the messages have been logged to a file rather than to
stdout.
"""
self.assertEqual([], stdout_messages)
logfile_messages = map(loads, logfile.getContent().splitlines())
assertContainsFields(
# message[0] contains a twisted log message.
self, logfile_messages[1], {u"key": 123}
)
d.addCallback(lambda messages: assertContainsFields(
self, messages[1], {u"message_type": u"twisted:log",
u"message": message,
u"error": True}))
return d
d.addCallback(lambda messages: assertContainsFields(
self, messages[1], {u"message_type": u"twisted:log",
u"message": u"hello",
u"error": False}))
return d
def got_messages(messages):
assertContainsFields(self, messages[1],
{u"message_type": u"twisted:log",
u"message": u"stdout!",
u"error": False})
assertContainsFields(self, messages[2],
{u"message_type": u"twisted:log",
u"message": u"stderr!",
u"error": True})
d.addCallback(got_messages)
d.addCallback(lambda messages: assertContainsFields(
self, messages[1], {u"message_type": u"twisted:log",
u"message": u"Received SIGINT, shutting down.",
u"error": False}))
return d
d.addCallback(lambda messages: assertContainsFields(self, messages[1],
{u"key": 123}))
return d
d.addCallback(lambda messages: assertContainsFields(self, messages[1],
{u"key": 123}))
return d
def got_messages(messages):
assertContainsFields(self, messages[1],
{u"message_type": u"twisted:log",
u"error": True})
self.assertTrue(messages[1][u"message"].startswith(
u"Unhandled Error\nTraceback (most recent call last):\n"))
self.assertTrue(messages[1][u"message"].endswith(
u"ZeroDivisionError: ono\n"))
d.addCallback(got_messages)