Coverage for tests/test_typing_python39.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1from fastapi import FastAPI 1fghijkl

2from fastapi.testclient import TestClient 1fghijkl

3 

4from .utils import needs_py310 1fghijkl

5 

6 

7@needs_py310 1fghijkl

8def test_typing(): 1fghijkl

9 types = { 1abcde

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(): 1abcde

16 app = FastAPI() 1abcde

17 

18 @app.post("/", response_model=test_type) 1abcde

19 def post_endpoint(input: test_type): 1abcde

20 return input 1abcde

21 

22 res = TestClient(app).post("/", json=expect) 1abcde

23 assert res.status_code == 200, res.json() 1abcde

24 assert res.json() == expect 1abcde