Coverage for tests/test_typing_python39.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1from fastapi import FastAPI 1efghij

2from fastapi.testclient import TestClient 1efghij

3 

4from .utils import needs_py310 1efghij

5 

6 

7@needs_py310 1efghij

8def test_typing(): 1efghij

9 types = { 1abcd

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

16 app = FastAPI() 1abcd

17 

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

19 def post_endpoint(input: test_type): 1abcd

20 return input 1abcd

21 

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

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

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