本文整理汇总了Python中flak.Flak.new_context方法的典型用法代码示例。如果您正苦于以下问题:Python Flak.new_context方法的具体用法?Python Flak.new_context怎么用?Python Flak.new_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flak.Flak
的用法示例。
在下文中一共展示了Flak.new_context方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_json_as_unicode
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_json_as_unicode(self):
app = Flak(__name__)
app.config["JSON_AS_ASCII"] = True
with app.new_context() as cx:
rv = cx.dumps(u"\N{SNOWMAN}")
assert rv == '"\\u2603"'
app.config["JSON_AS_ASCII"] = False
with app.new_context() as cx:
rv = cx.dumps(u"\N{SNOWMAN}")
assert rv == u'"\u2603"'
示例2: test_g_iteration_protocol
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_g_iteration_protocol():
app = Flak(__name__)
with app.new_context() as cx:
cx.globals.foo = 23
cx.globals.bar = 42
assert 'foo' in cx.globals
assert 'foos' not in cx.globals
assert sorted(cx.globals) == ['bar', 'foo']
示例3: test_get_method_on_g
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_get_method_on_g():
app = Flak(__name__)
with app.new_context() as cx:
assert cx.globals.get('x') is None
assert cx.globals.get('x', 11) == 11
cx.globals.x = 42
assert cx.globals.get('x') == 42
assert cx.globals.x == 42
示例4: test_app_tearing_down
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_app_tearing_down():
cleanup_stuff = []
app = Flak(__name__)
@app.teardown
def cleanup(cx, exception):
cleanup_stuff.append(exception)
with app.new_context():
pass
assert cleanup_stuff == [None]
示例5: test_basic_url_generation
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_basic_url_generation():
app = Flak(__name__)
app.config['SERVER_NAME'] = 'localhost'
app.config['PREFERRED_URL_SCHEME'] = 'https'
@app.route('/')
def index(cx):
pass
with app.new_context() as cx:
rv = cx.url_for('index')
assert rv == 'https://localhost/'
示例6: test_app_tearing_down_with_handled_exception
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_app_tearing_down_with_handled_exception():
cleanup_stuff = []
app = Flak(__name__)
@app.teardown
def cleanup(cx, exception):
cleanup_stuff.append(exception)
with app.new_context():
try:
raise Exception('dummy')
except Exception:
pass
assert cleanup_stuff == [None]
示例7: test_app_context_globals_methods
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_app_context_globals_methods():
app = Flak(__name__)
with app.new_context() as cx:
# get
assert cx.globals.get('foo') is None
assert cx.globals.get('foo', 'bar') == 'bar'
# __contains__
assert 'foo' not in cx.globals
cx.globals.foo = 'bar'
assert 'foo' in cx.globals
# setdefault
cx.globals.setdefault('bar', 'the cake is a lie')
cx.globals.setdefault('bar', 'hello world')
assert cx.globals.bar == 'the cake is a lie'
# pop
assert cx.globals.pop('bar') == 'the cake is a lie'
with pytest.raises(KeyError):
cx.globals.pop('bar')
assert cx.globals.pop('bar', 'more cake') == 'more cake'
# __iter__
assert list(cx.globals) == ['foo']
示例8: test_new_context
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_new_context():
app = Flak(__name__)
with app.new_context() as cx:
assert cx.app is app
示例9: test_url_generation_requires_server_name
# 需要导入模块: from flak import Flak [as 别名]
# 或者: from flak.Flak import new_context [as 别名]
def test_url_generation_requires_server_name():
app = Flak(__name__)
with app.new_context() as cx:
with pytest.raises(RuntimeError):
cx.url_for('index')