Coverage for tests/test_operations_signatures.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1import inspect 1abcde

2 

3from fastapi import APIRouter, FastAPI 1abcde

4 

5method_names = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] 1abcde

6 

7 

8def test_signatures_consistency(): 1abcde

9 base_sig = inspect.signature(APIRouter.get) 1abcde

10 for method_name in method_names: 1abcde

11 router_method = getattr(APIRouter, method_name) 1abcde

12 app_method = getattr(FastAPI, method_name) 1abcde

13 router_sig = inspect.signature(router_method) 1abcde

14 app_sig = inspect.signature(app_method) 1abcde

15 param: inspect.Parameter 

16 for key, param in base_sig.parameters.items(): 1abcde

17 router_param: inspect.Parameter = router_sig.parameters[key] 1abcde

18 app_param: inspect.Parameter = app_sig.parameters[key] 1abcde

19 assert param.annotation == router_param.annotation 1abcde

20 assert param.annotation == app_param.annotation 1abcde

21 assert param.default == router_param.default 1abcde

22 assert param.default == app_param.default 1abcde