Skip to content

Commit

Permalink
chore: refactor dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Nov 8, 2023
1 parent 25ee508 commit 3fb90a3
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 51 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
# Python
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
2 changes: 1 addition & 1 deletion docs/docs/tutorial/annotated.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ func(user_id=1) # correct calling
Like in the following example

```python
def func(user_id: Annotated[int: Field(...)], user: CurrentUser): ...
def func(user_id: Annotated[int, Field(...)], user: CurrentUser): ...
```
2 changes: 1 addition & 1 deletion fast_depends/__about__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System"""

__version__ = "2.2.1"
__version__ = "2.2.2"
20 changes: 8 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,13 @@ dynamic = ["version"]

dependencies = [
"pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0",
"anyio",
"anyio>=3.0.0,<5.0.0",
]

[project.optional-dependencies]
test = [
"coverage[toml]>=7.2",
"pytest>=7",
"pytest-asyncio>=0.21",
"pytest-xdist[psutil]",

"asyncmock; python_version < '3.8'",
"coverage[toml]==7.3.2",
"pytest==7.4.3",
]

doc = [
Expand All @@ -66,11 +62,11 @@ dev = [
"fast-depends[test]",
"fast-depends[doc]",

"mypy>=1.1",
"black>=23.3.0",
"isort>=5",
"ruff>=0.0.260",
"pyupgrade-directories",
"mypy==1.6.1",
"black==23.11.0",
"isort==5.12.0",
"ruff==0.1.4",
"pyupgrade-directories==0.3.0",
]

[project.urls]
Expand Down
30 changes: 15 additions & 15 deletions tests/async/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fast_depends import inject


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_not_annotated():
@inject
async def some_func(a, b):
Expand All @@ -16,7 +16,7 @@ async def some_func(a, b):
assert isinstance(await some_func("1", "2"), str)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_annotated_partial():
@inject
async def some_func(a, b: int):
Expand All @@ -26,7 +26,7 @@ async def some_func(a, b: int):
assert isinstance(await some_func(1, "2"), int)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_arbitrary_args():
class ArbitraryType:
def __init__(self):
Expand All @@ -39,7 +39,7 @@ async def some_func(a: ArbitraryType):
assert isinstance(await some_func(ArbitraryType()), ArbitraryType)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_arbitrary_response():
class ArbitraryType:
def __init__(self):
Expand All @@ -52,7 +52,7 @@ async def some_func(a: ArbitraryType) -> ArbitraryType:
assert isinstance(await some_func(ArbitraryType()), ArbitraryType)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_types_casting():
@inject
async def some_func(a: int, b: int) -> float:
Expand All @@ -65,7 +65,7 @@ async def some_func(a: int, b: int) -> float:
assert isinstance(await some_func("1", "2"), float)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_types_casting_from_str():
@inject
async def some_func(a: "int") -> float:
Expand All @@ -74,7 +74,7 @@ async def some_func(a: "int") -> float:
assert isinstance(await some_func("1"), float)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_pydantic_types_casting():
class SomeModel(BaseModel):
field: int
Expand All @@ -86,7 +86,7 @@ async def some_func(a: SomeModel):
assert isinstance(await some_func({"field": "31"}), int)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_pydantic_field_types_casting():
@inject
async def some_func(a: int = Field(..., alias="b")) -> float:
Expand All @@ -102,7 +102,7 @@ async def another_func(a=Field(..., alias="b")) -> float:
assert isinstance(await another_func(b="2"), float)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_wrong_incoming_types():
@inject
async def some_func(a: int): # pragma: no cover
Expand All @@ -112,7 +112,7 @@ async def some_func(a: int): # pragma: no cover
await some_func({"key", 1})


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_wrong_return_types():
@inject
async def some_func(a: int) -> dict:
Expand All @@ -122,7 +122,7 @@ async def some_func(a: int) -> dict:
await some_func("2")


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_annotated():
A = Annotated[int, Field(..., alias="b")]

Expand All @@ -134,7 +134,7 @@ async def some_func(a: A) -> float:
assert isinstance(await some_func(b="2"), float)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_args_kwargs_1():
@inject
async def simple_func(
Expand All @@ -150,7 +150,7 @@ async def simple_func(
)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_args_kwargs_2():
@inject
async def simple_func(
Expand All @@ -168,7 +168,7 @@ async def simple_func(
)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_args_kwargs_3():
@inject
async def simple_func(a: int, *, b: int):
Expand All @@ -180,7 +180,7 @@ async def simple_func(a: int, *, b: int):
)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_generator():
@inject
async def simple_func(a: str) -> int:
Expand Down
36 changes: 18 additions & 18 deletions tests/async/test_depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from fast_depends import Depends, inject


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_depends():
async def dep_func(b: int, a: int = 3) -> float:
return a + b
Expand All @@ -22,7 +22,7 @@ async def some_func(b: int, c=Depends(dep_func)) -> int:
assert (await some_func("2")) == 7


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_sync_depends():
def dep_func(a: int) -> float:
return a
Expand All @@ -35,7 +35,7 @@ async def some_func(a: int, b: int, c=Depends(dep_func)) -> float:
assert await some_func("1", "2")


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_depends_response_cast():
async def dep_func(a):
return a
Expand All @@ -48,7 +48,7 @@ async def some_func(a: int, b: int, c: int = Depends(dep_func)) -> float:
assert await some_func("1", "2")


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_depends_error():
async def dep_func(b: dict, a: int = 3) -> float: # pragma: no cover
return a + b
Expand All @@ -67,7 +67,7 @@ async def some_func(
assert await some_func("2")


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_depends_annotated():
async def dep_func(a):
return a
Expand All @@ -87,7 +87,7 @@ async def another_func(a: int, c: D):
assert (await another_func(3)) == 6.0


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_cash():
mock = Mock()

Expand All @@ -107,7 +107,7 @@ async def some_func(a=Depends(dep_func), b=Depends(nested_dep_func)):
mock.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_yield():
mock = Mock()

Expand All @@ -127,7 +127,7 @@ async def some_func(a=Depends(dep_func)):
mock.exit.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_sync_yield():
mock = Mock()

Expand All @@ -147,7 +147,7 @@ async def some_func(a=Depends(dep_func)):
mock.exit.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_sync_yield_exception():
mock = Mock()

Expand All @@ -169,7 +169,7 @@ async def some_func(a=Depends(dep_func)):
assert not mock.exit.called


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_sync_yield_exception_start():
mock = Mock()

Expand All @@ -187,7 +187,7 @@ async def some_func(a=Depends(dep_func)): # pragma: no cover
assert not mock.called


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_sync_yield_exception_main():
mock = Mock()

Expand All @@ -211,7 +211,7 @@ async def some_func(a=Depends(dep_func)):
mock.exit.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_class_depends():
class MyDep:
def __init__(self, a: int):
Expand All @@ -226,7 +226,7 @@ async def some_func(a=Depends(MyDep)):
await some_func(3)


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_callable_class_depends():
class MyDep:
def __init__(self, a: int):
Expand All @@ -243,7 +243,7 @@ async def some_func(a=Depends(MyDep(3))): # noqa: B008
await some_func()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_async_callable_class_depends():
class MyDep:
def __init__(self, a: int):
Expand All @@ -260,7 +260,7 @@ async def some_func(a=Depends(MyDep(3).call)): # noqa: B008
await some_func()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_not_cast():
@dataclass
class A:
Expand All @@ -285,7 +285,7 @@ async def some_func(
assert (await some_func(1)) == 1


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_not_cast_main():
@dataclass
class A:
Expand All @@ -310,7 +310,7 @@ async def some_func(
assert (await some_func(1)) == 1


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_extra():
mock = Mock()

Expand All @@ -330,7 +330,7 @@ async def some_func():
mock.sync_call.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_generator():
mock = Mock()

Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest


@pytest.fixture
def anyio_backend():
return "asyncio"
Empty file added tests/library/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions tests/library/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def sync_catch(key: int = Header()): # noqa: B008
assert sync_catch(headers={"key": "1"}) == 1


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_header_async():
@inject
async def async_catch(key: int = Header()): # noqa: B008
Expand All @@ -48,7 +48,7 @@ def sync_catch(key: str = Header(), key2: int = Header()): # noqa: B008
sync_catch(headers={"key": "1", "key2": "2"})


@pytest.mark.asyncio
@pytest.mark.anyio
async def test_async_header_async():
@inject
async def async_catch(key: float = AsyncHeader()): # noqa: B008
Expand Down
Loading

0 comments on commit 3fb90a3

Please sign in to comment.