'A L{FileLogObserver} created by L{jsonFileLogObserver} writes failures
serialized as JSON text to a file when it observes events.'

def test_failureFormatting(self):

    io = StringIO()
    publisher = LogPublisher()
    logged = []
    publisher.addObserver(logged.append)
    publisher.addObserver(jsonFileLogObserver(io))
    logger = Logger(observer=publisher)
    try:
        (1 / 0)
    except:
        logger.failure('failed    as    expected')
    reader = StringIO(io.getvalue())
    deserialized = list(eventsFromJSONLogFile(reader))
    def checkEvents(logEvents):
        self.assertEqual(len(logEvents), 1)
        [failureEvent] = logEvents
        self.assertIn('log_failure', failureEvent)
        failureObject = failureEvent['log_failure']
        self.assertIsInstance(failureObject, Failure)
        tracebackObject = failureObject.getTracebackObject()
        self.assertEqual(tracebackObject.tb_frame.f_code.co_filename.rstrip('co'), __file__.rstrip('co'))
    checkEvents(logged)
    checkEvents(deserialized)
