Skip to content

Commit 09590d1

Browse files
committed
Typing and codestyle
1 parent eb0f80e commit 09590d1

File tree

6 files changed

+53
-25
lines changed

6 files changed

+53
-25
lines changed

tests/repository/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import os
2-
from typing import Iterator, Union
2+
from typing import Iterator, Type, Union
33
from uuid import uuid4
44

55
import pytest
@@ -49,7 +49,7 @@ def sync_async_sa_manager(multiple_config) -> Iterator[SQLAlchemyBindManager]:
4949
@pytest.fixture
5050
def repository_class(
5151
sa_bind: Union[SQLAlchemyBind, SQLAlchemyAsyncBind]
52-
) -> Union[SQLAlchemyAsyncRepository, SQLAlchemyRepository]:
52+
) -> Type[Union[SQLAlchemyAsyncRepository, SQLAlchemyRepository]]:
5353
base_class = (
5454
SQLAlchemyRepository
5555
if isinstance(sa_bind, SQLAlchemyBind)

tests/repository/test_delete_many.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import pytest
2-
from sqlalchemy import select
32

43

5-
async def test_can_delete_by_instance(repository_class, model_class, sa_bind, sync_async_wrapper):
4+
async def test_can_delete_by_instance(
5+
repository_class, model_class, sa_bind, sync_async_wrapper
6+
):
67
model = model_class(
78
model_id=1,
89
name="Someone",
@@ -36,14 +37,16 @@ async def test_delete_inexistent_raises_exception(
3637
await sync_async_wrapper(repo.delete_many([4]))
3738

3839
with pytest.raises(Exception):
39-
await sync_async_wrapper(repo.delete_many(
40-
[
41-
model_class(
42-
model_id=823,
43-
name="Someone",
44-
)
45-
]
46-
))
40+
await sync_async_wrapper(
41+
repo.delete_many(
42+
[
43+
model_class(
44+
model_id=823,
45+
name="Someone",
46+
)
47+
]
48+
)
49+
)
4750

4851

4952
async def test_relationships_are_respected(

tests/repository/test_find.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ async def test_find(repository_class, model_class, sa_bind, sync_async_wrapper):
2121
assert len(results) == 3
2222

2323

24-
async def test_find_filtered(repository_class, model_class, sa_bind, sync_async_wrapper):
24+
async def test_find_filtered(
25+
repository_class, model_class, sa_bind, sync_async_wrapper
26+
):
2527
model = model_class(
2628
name="Someone",
2729
)
@@ -38,7 +40,9 @@ async def test_find_filtered(repository_class, model_class, sa_bind, sync_async_
3840
assert len(results) == 1
3941

4042

41-
async def test_find_filtered_fails_if_invalid_filter(repository_class, model_class, sa_bind, sync_async_wrapper):
43+
async def test_find_filtered_fails_if_invalid_filter(
44+
repository_class, model_class, sa_bind, sync_async_wrapper
45+
):
4246
repo = repository_class(bind=sa_bind, model_class=model_class)
4347
with pytest.raises(UnmappedProperty):
4448
await sync_async_wrapper(repo.find(search_params={"somename": "Someone"}))
@@ -58,16 +62,22 @@ async def test_find_ordered(repository_class, model_class, sa_bind, sync_async_w
5862
assert results[0].name == "Abbott"
5963
assert results[1].name == "Costello"
6064

61-
results2 = await sync_async_wrapper(repo.find(order_by=(("name", SortDirection.ASC),)))
65+
results2 = await sync_async_wrapper(
66+
repo.find(order_by=(("name", SortDirection.ASC),))
67+
)
6268
assert results2[0].name == "Abbott"
6369
assert results2[1].name == "Costello"
6470

65-
results3 = await sync_async_wrapper(repo.find(order_by=(("name", SortDirection.DESC),)))
71+
results3 = await sync_async_wrapper(
72+
repo.find(order_by=(("name", SortDirection.DESC),))
73+
)
6674
assert results3[1].name == "Abbott"
6775
assert results3[0].name == "Costello"
6876

6977

70-
async def test_find_ordered_fails_if_invalid_column(repository_class, model_class, sa_bind, sync_async_wrapper):
78+
async def test_find_ordered_fails_if_invalid_column(
79+
repository_class, model_class, sa_bind, sync_async_wrapper
80+
):
7181
repo = repository_class(bind=sa_bind, model_class=model_class)
7282
with pytest.raises(UnmappedProperty):
7383
await repo.find(order_by=("unexisting",))

tests/repository/test_get.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import pytest
22

33

4-
async def test_get_returns_model(repository_class, model_class, sa_bind, sync_async_wrapper):
4+
async def test_get_returns_model(
5+
repository_class, model_class, sa_bind, sync_async_wrapper
6+
):
57
model = model_class(
68
model_id=1,
79
name="Someone",
@@ -19,7 +21,9 @@ async def test_get_returns_model(repository_class, model_class, sa_bind, sync_as
1921
assert isinstance(result, model_class)
2022

2123

22-
async def test_get_many_returns_models(repository_class, model_class, sa_bind, sync_async_wrapper):
24+
async def test_get_many_returns_models(
25+
repository_class, model_class, sa_bind, sync_async_wrapper
26+
):
2327
model = model_class(
2428
model_id=1,
2529
name="Someone",
@@ -52,7 +56,9 @@ async def test_get_many_returns_empty_list_if_nothing_found(
5256
assert len(result) == 0
5357

5458

55-
async def test_get_raises_exception_if_not_found(repository_class, model_class, sa_bind, sync_async_wrapper):
59+
async def test_get_raises_exception_if_not_found(
60+
repository_class, model_class, sa_bind, sync_async_wrapper
61+
):
5662
repo = repository_class(bind=sa_bind, model_class=model_class)
5763

5864
with pytest.raises(Exception):

tests/repository/test_repository_lifecycle.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
from sqlalchemy_bind_manager.repository import SQLAlchemyAsyncRepository
1111

1212

13-
def test_repository_fails_if_not_correct_bind(sa_manager, repository_class, model_class):
13+
def test_repository_fails_if_not_correct_bind(
14+
sa_manager, repository_class, model_class
15+
):
1416
wrong_bind = "sync" if repository_class is SQLAlchemyAsyncRepository else "async"
1517

1618
with pytest.raises(UnsupportedBind):

tests/repository/test_save.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import AsyncMock, patch, MagicMock
1+
from unittest.mock import AsyncMock, MagicMock, patch
22

33
import pytest
44
from sqlalchemy.ext.asyncio import AsyncSession
@@ -17,7 +17,9 @@ async def test_save_model(repository_class, model_class, sa_bind, sync_async_wra
1717
assert model.model_id is not None
1818

1919

20-
async def test_save_many_models(repository_class, model_class, sa_bind, sync_async_wrapper):
20+
async def test_save_many_models(
21+
repository_class, model_class, sa_bind, sync_async_wrapper
22+
):
2123
model = model_class(
2224
name="Someone",
2325
)
@@ -42,13 +44,18 @@ class SomeTestException(Exception):
4244
name="Someone",
4345
)
4446

45-
session_class = AsyncSession if isinstance(sa_bind, SQLAlchemyAsyncBind) else Session
47+
session_class = (
48+
AsyncSession if isinstance(sa_bind, SQLAlchemyAsyncBind) else Session
49+
)
4650
session_mock = AsyncMock if isinstance(sa_bind, SQLAlchemyAsyncBind) else MagicMock
4751

4852
with patch.object(
4953
session_class, "rollback", new_callable=session_mock, return_value=None
5054
) as mocked_rollback, patch.object(
51-
session_class, "commit", new_callable=session_mock, side_effect=SomeTestException
55+
session_class,
56+
"commit",
57+
new_callable=session_mock,
58+
side_effect=SomeTestException,
5259
):
5360
repo = repository_class(bind=sa_bind, model_class=model_class)
5461

0 commit comments

Comments
 (0)