本文整理汇总了Python中flak.Flak.config['LOGGER_HANDLER_POLICY']方法的典型用法代码示例。如果您正苦于以下问题:Python Flak.config['LOGGER_HANDLER_POLICY']方法的具体用法?Python Flak.config['LOGGER_HANDLER_POLICY']怎么用?Python Flak.config['LOGGER_HANDLER_POLICY']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flak.Flak
的用法示例。
在下文中一共展示了Flak.config['LOGGER_HANDLER_POLICY']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_test_client_context_binding
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import config['LOGGER_HANDLER_POLICY'] [as 别名]
def test_test_client_context_binding():
app = Flak(__name__)
app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.route('/')
def index(cx):
cx.globals.value = 42
return 'Hello World!'
@app.route('/other')
def other(cx):
cx.globals.value = 23
1 // 0
with app.test_client() as c:
resp = c.get('/')
cx = c.captured_context
assert cx.globals.value == 42
assert resp.data == b'Hello World!'
assert resp.status_code == 200
resp = c.get('/other')
assert b'Internal Server Error' in resp.data
assert resp.status_code == 500
assert c.captured_context is not cx
cx = c.captured_context
assert cx.globals.value == 23
示例2: apprunner
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import config['LOGGER_HANDLER_POLICY'] [as 别名]
def apprunner(config_key):
app = Flak(__name__)
app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.route('/')
def index(cx):
1 // 0
c = app.test_client()
if config_key is not None:
app.config[config_key] = True
try:
c.get('/')
except Exception:
pass
else:
assert False, 'expected exception'
else:
assert c.get('/').status_code == 500
示例3: test_error_handling
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import config['LOGGER_HANDLER_POLICY'] [as 别名]
def test_error_handling():
app = Flak(__name__)
app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.errorhandler(404)
def not_found(cx, e):
return 'not found', 404
@app.errorhandler(500)
def internal_server_error(cx, e):
return 'internal server error', 500
@app.errorhandler(Forbidden)
def forbidden(cx, e):
return 'forbidden', 403
@app.route('/')
def index(cx):
flak.abort(404)
@app.route('/error')
def error(cx):
1 // 0
@app.route('/forbidden')
def error2(cx):
flak.abort(403)
c = app.test_client()
rv = c.get('/')
assert rv.status_code == 404
assert rv.data == b'not found'
rv = c.get('/error')
assert rv.status_code == 500
assert b'internal server error' == rv.data
rv = c.get('/forbidden')
assert rv.status_code == 403
assert b'forbidden' == rv.data
示例4: test_teardown_request_handler_error
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import config['LOGGER_HANDLER_POLICY'] [as 别名]
def test_teardown_request_handler_error():
called = []
app = Flak(__name__)
app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.teardown
def teardown_request1(cx, exc):
assert type(exc) == ZeroDivisionError
called.append(True)
# This raises a new error and blows away sys.exc_info(), so we can
# test that all teardown_requests get passed the same original
# exception.
try:
raise TypeError()
except:
pass
@app.teardown
def teardown_request2(cx, exc):
assert type(exc) == ZeroDivisionError
called.append(True)
# This raises a new error and blows away sys.exc_info(), so we can
# test that all teardown_requests get passed the same original
# exception.
try:
raise TypeError()
except:
pass
@app.route('/')
def fails(cx):
1 // 0
rv = app.test_client().get('/')
assert rv.status_code == 500
assert b'Internal Server Error' in rv.data
assert len(called) == 2