Beispiel #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)
Beispiel #2
0
 def test_isatty(self):
     assert not FileLogProxy(get_logger('foo')).isatty()
Beispiel #3
0
 def test_flush(self):
     FileLogProxy(get_logger('foo')).flush()
Beispiel #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'),
        ])
Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #8
0
 def test_flush(self):
     FileLogProxy(get_logger("foo")).flush()
Beispiel #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"),
        ])