def test_trap_output(self): class BorkedOutput(outputs.ListOutput): def _write(self, x): raise RuntimeError("BORK") out = BorkedOutput(close_atexit=False) sio = StringIO() def cleanup(stderr, output): sys.stderr = stderr sio.close() self.log.output = output out.close() self.addCleanup(cleanup, sys.stderr, self.log.output) sys.stderr = sio self.log.output = out self.log.fields().info("hi") assert "BORK" in sio.getvalue() assert "Offending message: <twiggy.message.Message object" in sio.getvalue() assert "Error in twiggy internal log! Something is serioulsy broken." in sio.getvalue() assert "Traceback" in sio.getvalue()
def test_trap_output(self): class BorkedOutput(outputs.ListOutput): def _write(self, x): raise RuntimeError("BORK") out = BorkedOutput(close_atexit=False) sio = StringIO() def cleanup(stderr, output): sys.stderr = stderr sio.close() self.log.output = output out.close() self.addCleanup(cleanup, sys.stderr, self.log.output) sys.stderr = sio self.log.output = out self.log.fields().info('hi') assert "BORK" in sio.getvalue() assert "Offending message: <twiggy.message.Message object" in sio.getvalue( ) assert "Error in twiggy internal log! Something is serioulsy broken." in sio.getvalue( ) assert "Traceback" in sio.getvalue()
def test_stream_output(self): sio = StringIO() o = outputs.StreamOutput(formats.shell_format, sio) o.output(m) o.close() assert sio.getvalue( ) == "DEBUG:jose:shirt=42|Hello Mister Funnypants\n"
def test_trap_msg(self): sio = StringIO() def cleanup(stderr): sys.stderr = stderr sio.close() self.addCleanup(cleanup, sys.stderr) sys.stderr = sio def go_boom(): raise RuntimeError("BOOM") self.log.fields(func=go_boom).info("hi") assert "BOOM" in sio.getvalue() assert "Offending message: None" in sio.getvalue() assert "Error in twiggy internal log! Something is serioulsy broken." in sio.getvalue() assert "Traceback" in sio.getvalue()
def test_trap_msg(self): sio = StringIO() def cleanup(stderr): sys.stderr = stderr sio.close() self.addCleanup(cleanup, sys.stderr) sys.stderr = sio def go_boom(): raise RuntimeError("BOOM") self.log.fields(func=go_boom).info('hi') assert "BOOM" in sio.getvalue() assert "Offending message: None" in sio.getvalue() assert "Error in twiggy internal log! Something is serioulsy broken." in sio.getvalue( ) assert "Traceback" in sio.getvalue()
def test_stream_output(self): sio = StringIO() o = outputs.StreamOutput(formats.shell_format, sio) o.output(m) o.close() assert sio.getvalue() == "DEBUG:jose:shirt=42|Hello Mister Funnypants\n"