本文整理汇总了Python中flak.Flak.debug方法的典型用法代码示例。如果您正苦于以下问题:Python Flak.debug方法的具体用法?Python Flak.debug怎么用?Python Flak.debug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flak.Flak
的用法示例。
在下文中一共展示了Flak.debug方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_preserve_remembers_exception
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_preserve_remembers_exception():
app = Flak(__name__)
app.debug = True
errors = []
@app.route('/fail')
def fail_func(cx):
1 // 0
@app.route('/success')
def success_func(cx):
return 'Okay'
@app.teardown
def teardown_handler(cx, exc):
errors.append(exc)
c = app.test_client()
# After this failure we did not yet call the teardown handler
with pytest.raises(ZeroDivisionError):
c.get('/fail')
#assert errors == []
assert len(errors) == 1
# But this request triggers it, and it's an error
c.get('/success')
assert len(errors) == 2
# At this point another request does nothing.
c.get('/success')
assert len(errors) == 3
assert errors[1] is None
示例2: test_route_decorator_custom_endpoint
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_route_decorator_custom_endpoint():
app = Flak(__name__)
app.debug = True
@app.route('/foo/')
def foo(cx):
return cx.request.endpoint
@app.route('/bar/', endpoint='bar')
def for_bar(cx):
return cx.request.endpoint
@app.route('/bar/123', endpoint='123')
def for_bar_foo(cx):
return cx.request.endpoint
with app.test_context() as cx:
assert cx.url_for('foo') == '/foo/'
assert cx.url_for('bar') == '/bar/'
assert cx.url_for('123') == '/bar/123'
c = app.test_client()
assert c.get('/foo/').data == b'foo'
assert c.get('/bar/').data == b'bar'
assert c.get('/bar/123').data == b'123'
示例3: test_preserve_only_once
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_preserve_only_once():
app = Flak(__name__)
app.debug = True
@app.route('/fail')
def fail_func(cx):
1 // 0
with app.test_client() as c:
for x in range(3):
with pytest.raises(ZeroDivisionError):
c.get('/fail')
assert c.captured_context is not None
示例4: test_routing_redirect_debugging
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_routing_redirect_debugging():
app = Flak(__name__)
app.debug = True
@app.route('/foo/', methods=['GET', 'POST'])
def foo(cx):
return 'success'
with app.test_client() as c:
try:
c.post('/foo', data={})
except AssertionError as e:
assert 'http://localhost/foo/' in str(e)
assert ('Make sure to directly send '
'your POST-request to this URL') in str(e)
else:
assert False, 'Expected exception'
rv = c.get('/foo', data={}, follow_redirects=True)
assert rv.data == b'success'
app.debug = False
with app.test_client() as c:
rv = c.post('/foo', data={}, follow_redirects=True)
assert rv.data == b'success'
示例5: test_endpoint_override
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_endpoint_override():
app = Flak(__name__)
app.debug = True
class Index(views.View):
methods = ['GET', 'POST']
def dispatch_request(self, cx):
return cx.request.method
app.add_url_rule('/', Index.as_view('index'))
with pytest.raises(AssertionError):
app.add_url_rule('/', Index.as_view('index'))
# But these tests should still pass. We just log a warning.
common_asserts(app)
示例6: test_enctype_debug_helper
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_enctype_debug_helper():
from flak.debughelpers import DebugFilesKeyError
app = Flak(__name__)
app.debug = True
@app.route('/fail', methods=['POST'])
def index(cx):
return cx.request.files['foo'].filename
with app.test_client() as c:
try:
c.post('/fail', data={'foo': 'index.txt'})
except DebugFilesKeyError as e:
assert 'no file contents were transmitted' in str(e)
assert 'This was submitted: "index.txt"' in str(e)
else:
assert False, 'Expected exception'
示例7: test_debug_log
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_debug_log(self, capsys):
app = Flak(__name__)
app.debug = True
@app.route("/")
def index(cx):
app.logger.warning("the standard library is dead")
app.logger.debug("this is a debug statement")
return ""
@app.route("/exc")
def exc(cx):
1 // 0
with app.test_client() as c:
c.get("/")
out, err = capsys.readouterr()
assert "WARNING in test_helpers [" in err
assert os.path.basename(__file__.rsplit(".", 1)[0] + ".py") in err
assert "the standard library is dead" in err
assert "this is a debug statement" in err
with pytest.raises(ZeroDivisionError):
c.get("/exc")
示例8: test_debug_log_override
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import debug [as 别名]
def test_debug_log_override(self):
app = Flak(__name__)
app.debug = True
app.logger_name = "flak_tests/test_debug_log_override"
app.logger.level = 10
assert app.logger.level == 10