Example #1
0
 def test_redirect_stdouts(self):
     logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                root=False)
     try:
         with mock.wrap_logger(logger) as sio:
             self.app.log.redirect_stdouts_to_logger(
                 logger, loglevel=logging.ERROR,
             )
             logger.error('foo')
             assert 'foo' in sio.getvalue()
             self.app.log.redirect_stdouts_to_logger(
                 logger, stdout=False, stderr=False,
             )
     finally:
         sys.stdout, sys.stderr = sys.__stdout__, sys.__stderr__
Example #2
0
    def test_logging_proxy(self):
        logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                   root=False)

        with mock.wrap_logger(logger) as sio:
            p = LoggingProxy(logger, loglevel=logging.ERROR)
            p.close()
            p.write('foo')
            assert 'foo' not in sio.getvalue()
            p.closed = False
            p.write('foo')
            assert 'foo' in sio.getvalue()
            lines = ['baz', 'xuzzy']
            p.writelines(lines)
            for line in lines:
                assert line in sio.getvalue()
            p.flush()
            p.close()
            assert not p.isatty()

            with mock.stdouts() as (stdout, stderr):
                with in_sighandler():
                    p.write('foo')
                    assert stderr.getvalue()