MCPcopy
hub / github.com/encode/uvicorn / test_app_factory

Function test_app_factory

tests/test_config.py:227–248  ·  tests/test_config.py::test_app_factory
(caplog: pytest.LogCaptureFixture)

Source from the content-addressed store, hash-verified

225
226
227def test_app_factory(caplog: pytest.LogCaptureFixture) -> None:
228 def create_app() -> ASGIApplication:
229 return asgi_app
230
231 config = Config(app=create_app, factory=True, proxy_headers=False)
232 config.load()
233 assert config.loaded_app is asgi_app
234
235 class="cm"># Flag not passed. In this case, successfully load the app, but issue a warning
236 class="cm"># to indicate that an explicit flag is preferred.
237 caplog.clear()
238 config = Config(app=create_app, proxy_headers=False)
239 with caplog.at_level(logging.WARNING):
240 config.load()
241 assert config.loaded_app is asgi_app
242 assert len(caplog.records) == 1
243 assert class="st">"--factory" in caplog.records[0].message
244
245 class="cm"># App not a no-arguments callable.
246 config = Config(app=asgi_app, factory=True)
247 with pytest.raises(SystemExit):
248 config.load()
249
250
251def test_concrete_http_class() -> None:

Callers

nothing calls this directly

Calls 3

loadMethod · 0.95
ConfigClass · 0.90
clearMethod · 0.80

Tested by

no test coverage detected