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)
def test_isatty(self): assert not FileLogProxy(get_logger('foo')).isatty()
def test_flush(self): FileLogProxy(get_logger('foo')).flush()
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'), ])
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
def test_constructor__severity_from_logger(self): logger = get_logger('foo') logger.level = logging.DEBUG f = FileLogProxy(logger) assert f.severity == logging.DEBUG
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
def test_flush(self): FileLogProxy(get_logger("foo")).flush()
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"), ])