| 1 |
import inspect |
| 2 |
|
| 3 |
from fastapi import APIRouter, FastAPI |
| 4 |
|
| 5 |
method_names = ["get", "put", "post", "delete", "options", "head", "patch", "trace"] |
| 6 |
|
| 7 |
|
| 8 |
def test_signatures_consistency(): |
| 9 |
base_sig = inspect.signature(APIRouter.get) |
| 10 |
for method_name in method_names: |
| 11 |
router_method = getattr(APIRouter, method_name) |
| 12 |
app_method = getattr(FastAPI, method_name) |
| 13 |
router_sig = inspect.signature(router_method) |
| 14 |
app_sig = inspect.signature(app_method) |
| 15 |
param: inspect.Parameter |
| 16 |
for key, param in base_sig.parameters.items(): |
| 17 |
router_param: inspect.Parameter = router_sig.parameters[key] |
| 18 |
app_param: inspect.Parameter = app_sig.parameters[key] |
| 19 |
assert param.annotation == router_param.annotation |
| 20 |
assert param.annotation == app_param.annotation |
| 21 |
assert param.default == router_param.default |
| 22 |
assert param.default == app_param.default |