Exemplo n.º 1
0
    def test__safewrap_handler(self):
        f = FileLogProxy(get_logger('foo'))
        handler = Mock()
        f._safewrap_handler(handler)

        with patch('traceback.print_exc') as print_exc:
            record = Mock()
            handler.handleError(record)
            print_exc.assert_called_once_with(None, sys.__stderr__)
            print_exc.side_effect = IOError()
            handler.handleError(record)
Exemplo n.º 2
0
 def test_isatty(self):
     assert not FileLogProxy(get_logger('foo')).isatty()
Exemplo n.º 3
0
 def test_flush(self):
     FileLogProxy(get_logger('foo')).flush()
Exemplo n.º 4
0
    def test_write(self):
        logger = Mock(handlers=[])
        f = FileLogProxy(logger)
        f._threadlocal.recurse_protection = True
        f.write('foo')
        logger.log.assert_not_called()

        f._threadlocal.recurse_protection = False
        f.write('')
        f.write('               ')
        f.close()
        f.write('msg')
        logger.log.assert_not_called()

        f._closed = False
        f.write(' msg ')
        logger.log.assert_called_once_with(f.severity, 'msg')

        f.writelines(['foo', 'bar'])
        logger.log.assert_has_calls([
            call(f.severity, 'msg'),
            call(f.severity, 'foo'),
            call(f.severity, 'bar'),
        ])
Exemplo n.º 5
0
 def test_constructor__explicit_severity(self):
     logger = get_logger('foo')
     logger.level = logging.DEBUG
     f = FileLogProxy(logger, severity=logging.ERROR)
     assert f.severity == logging.ERROR
Exemplo n.º 6
0
 def test_constructor__severity_from_logger(self):
     logger = get_logger('foo')
     logger.level = logging.DEBUG
     f = FileLogProxy(logger)
     assert f.severity == logging.DEBUG
Exemplo n.º 7
0
 def test_constructor__defaults(self):
     logger = get_logger('foo')
     logger.level = None
     assert logger.level is None
     f = FileLogProxy(logger)
     assert f.severity == logging.WARN
Exemplo n.º 8
0
 def test_flush(self):
     FileLogProxy(get_logger("foo")).flush()
Exemplo n.º 9
0
    def test_write(self):
        logger = Mock(handlers=[])
        f = FileLogProxy(logger)
        f._threadlocal.recurse_protection = True
        f.write("foo")
        logger.log.assert_not_called()

        f._threadlocal.recurse_protection = False
        f.write("")
        f.write("               ")
        f.close()
        f.write("msg")
        logger.log.assert_not_called()

        f._closed = False
        f.write(" msg ")
        logger.log.assert_called_once_with(f.severity, "msg")

        f.writelines(["foo", "bar"])
        logger.log.assert_has_calls([
            call(f.severity, "msg"),
            call(f.severity, "foo"),
            call(f.severity, "bar"),
        ])