Coverage for tests/pydantic_specific/test_custom.py: 100%
22 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 05:19 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-13 05:19 +0000
1from typing import Annotated, Any 1klabmcndoefghij
3import pytest 1klabmcndoefghij
4from annotated_types import Ge 1klabmcndoefghij
6from fast_depends import inject 1klabmcndoefghij
7from fast_depends.exceptions import ValidationError 1klabmcndoefghij
8from fast_depends.library import CustomField 1klabmcndoefghij
9from tests.marks import pydanticV2 1klabmcndoefghij
12class Header(CustomField): 1klabmcndoefghij
13 def use(self, /, **kwargs: Any) -> dict[str, Any]: 1klabmcndoefghij
14 kwargs = super().use(**kwargs) 1abcdefghij
15 if v := kwargs.get("headers", {}).get(self.param_name): 1abcdefghij
16 kwargs[self.param_name] = v 1abcdefghij
17 return kwargs 1abcdefghij
20@pydanticV2 1klabmcndoefghij
21def test_annotated_header_with_meta() -> None: 1klabmcndoefghij
22 @inject() 1abcdefghij
23 def sync_catch(key: Annotated[int, Header(), Ge(3)] = 3) -> int: 1abcdefghij
24 return key 1abcdefghij
26 assert sync_catch(headers={"key": "4"}) == 4 1abcdefghij
28 assert sync_catch(headers={}) == 3 1abcdefghij
30 with pytest.raises(ValidationError): 1abcdefghij
31 sync_catch(headers={"key": "2"}) 1abcdefghij