同步操作将从 Gitee 极速下载/FastAPI 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from typing import AsyncGenerator, Generatorimport pytestfrom fastapi import Depends, FastAPIfrom fastapi.testclient import TestClientapp = FastAPI()class CallableDependency:def __call__(self, value: str) -> str:return valueclass CallableGenDependency:def __call__(self, value: str) -> Generator[str, None, None]:yield valueclass AsyncCallableDependency:async def __call__(self, value: str) -> str:return valueclass AsyncCallableGenDependency:async def __call__(self, value: str) -> AsyncGenerator[str, None]:yield valueclass MethodsDependency:def synchronous(self, value: str) -> str:return valueasync def asynchronous(self, value: str) -> str:return valuedef synchronous_gen(self, value: str) -> Generator[str, None, None]:yield valueasync def asynchronous_gen(self, value: str) -> AsyncGenerator[str, None]:yield valuecallable_dependency = CallableDependency()callable_gen_dependency = CallableGenDependency()async_callable_dependency = AsyncCallableDependency()async_callable_gen_dependency = AsyncCallableGenDependency()methods_dependency = MethodsDependency()@app.get("/callable-dependency")async def get_callable_dependency(value: str = Depends(callable_dependency)):return value@app.get("/callable-gen-dependency")async def get_callable_gen_dependency(value: str = Depends(callable_gen_dependency)):return value@app.get("/async-callable-dependency")async def get_async_callable_dependency(value: str = Depends(async_callable_dependency),):return value@app.get("/async-callable-gen-dependency")async def get_async_callable_gen_dependency(value: str = Depends(async_callable_gen_dependency),):return value@app.get("/synchronous-method-dependency")async def get_synchronous_method_dependency(value: str = Depends(methods_dependency.synchronous),):return value@app.get("/synchronous-method-gen-dependency")async def get_synchronous_method_gen_dependency(value: str = Depends(methods_dependency.synchronous_gen),):return value@app.get("/asynchronous-method-dependency")async def get_asynchronous_method_dependency(value: str = Depends(methods_dependency.asynchronous),):return value@app.get("/asynchronous-method-gen-dependency")async def get_asynchronous_method_gen_dependency(value: str = Depends(methods_dependency.asynchronous_gen),):return valueclient = TestClient(app)@pytest.mark.parametrize("route,value",[("/callable-dependency", "callable-dependency"),("/callable-gen-dependency", "callable-gen-dependency"),("/async-callable-dependency", "async-callable-dependency"),("/async-callable-gen-dependency", "async-callable-gen-dependency"),("/synchronous-method-dependency", "synchronous-method-dependency"),("/synchronous-method-gen-dependency", "synchronous-method-gen-dependency"),("/asynchronous-method-dependency", "asynchronous-method-dependency"),("/asynchronous-method-gen-dependency", "asynchronous-method-gen-dependency"),],)def test_class_dependency(route, value):response = client.get(route, params={"value": value})assert response.status_code == 200, response.textassert response.json() == value
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。