def with_wrap_logger(sio): p = LoggingProxy(logger) p.close() p.write("foo") self.assertNotIn("foo", sio.getvalue()) p.closed = False p.write("foo") self.assertIn("foo", sio.getvalue()) lines = ["baz", "xuzzy"] p.writelines(lines) for line in lines: self.assertIn(line, sio.getvalue()) p.flush() p.close() self.assertFalse(p.isatty()) self.assertIsNone(p.fileno())
def test_logging_proxy(self): logger = self.setup_logger(loglevel=logging.ERROR, logfile=None, root=False) with wrap_logger(logger) as sio: p = LoggingProxy(logger, loglevel=logging.ERROR) p.close() p.write("foo") self.assertNotIn("foo", sio.getvalue()) p.closed = False p.write("foo") self.assertIn("foo", sio.getvalue()) lines = ["baz", "xuzzy"] p.writelines(lines) for line in lines: self.assertIn(line, sio.getvalue()) p.flush() p.close() self.assertFalse(p.isatty()) self.assertIsNone(p.fileno())