MCPcopy
hub / github.com/pallets/flask / test_app_ctx_globals_methods

Function test_app_ctx_globals_methods

tests/test_appctx.py:134–154  ·  view source on GitHub ↗
(app, app_ctx)

Source from the content-addressed store, hash-verified

132
133
134def test_app_ctx_globals_methods(app, app_ctx):
135 # get
136 assert flask.g.get("foo") is None
137 assert flask.g.get("foo", "bar") == "bar"
138 # __contains__
139 assert "foo" not in flask.g
140 flask.g.foo = "bar"
141 assert "foo" in flask.g
142 # setdefault
143 flask.g.setdefault("bar", "the cake is a lie")
144 flask.g.setdefault("bar", "hello world")
145 assert flask.g.bar == "the cake is a lie"
146 # pop
147 assert flask.g.pop("bar") == "the cake is a lie"
148 with pytest.raises(KeyError):
149 flask.g.pop("bar")
150 assert flask.g.pop("bar", "more cake") == "more cake"
151 # __iter__
152 assert list(flask.g) == ["foo"]
153 # __repr__
154 assert repr(flask.g) == "<flask.g of 'flask_test'>"
155
156
157def test_custom_app_ctx_globals_class(app):

Callers

nothing calls this directly

Calls 3

setdefaultMethod · 0.80
getMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…