Coverage for tests/test_typing_python39.py: 100%
14 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi import FastAPI 1deabc
2from fastapi.testclient import TestClient 1deabc
4from .utils import needs_py310 1deabc
7@needs_py310 1deabc
8def test_typing(): 1deabc
9 types = { 1abc
10 list[int]: [1, 2, 3],
11 dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]},
12 set[int]: [1, 2, 3], # `set` is converted to `list`
13 tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list`
14 }
15 for test_type, expect in types.items(): 1abc
16 app = FastAPI() 1abc
18 @app.post("/", response_model=test_type) 1abc
19 def post_endpoint(input: test_type): 1abc
20 return input 1abc
22 res = TestClient(app).post("/", json=expect) 1abc
23 assert res.status_code == 200, res.json() 1abc
24 assert res.json() == expect 1abc