Skip to content

Commit 6b9093e

Browse files
committed
Exception PEP8 naming
1 parent f52b028 commit 6b9093e

File tree

14 files changed

+56
-56
lines changed

14 files changed

+56
-56
lines changed

sqlalchemy_bind_manager/_bind_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
from sqlalchemy.orm.decl_api import DeclarativeMeta, registry
3434

3535
from sqlalchemy_bind_manager.exceptions import (
36-
InvalidConfig,
37-
NotInitializedBind,
36+
InvalidConfigError,
37+
NotInitializedBindError,
3838
)
3939

4040

@@ -99,7 +99,7 @@ def __init_bind(
9999
isinstance(config, SQLAlchemyAsyncConfig),
100100
]
101101
):
102-
raise InvalidConfig(
102+
raise InvalidConfigError(
103103
f"Config for bind `{name}` is not a SQLAlchemyConfig"
104104
f" or SQLAlchemyAsyncConfig object"
105105
)
@@ -181,7 +181,7 @@ def get_bind(
181181
try:
182182
return self.__binds[bind_name]
183183
except KeyError:
184-
raise NotInitializedBind("Bind not initialized")
184+
raise NotInitializedBindError("Bind not initialized")
185185

186186
def get_session(
187187
self, bind_name: str = DEFAULT_BIND_NAME

sqlalchemy_bind_manager/_repository/async_.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
from .._bind_manager import SQLAlchemyAsyncBind
3939
from .._session_handler import AsyncSessionHandler
40-
from ..exceptions import InvalidConfig, ModelNotFound
40+
from ..exceptions import InvalidConfigError, ModelNotFoundError
4141
from .base_repository import (
4242
BaseRepository,
4343
)
@@ -72,7 +72,7 @@ def __init__(
7272
"""
7373
super().__init__(model_class=model_class)
7474
if not (bool(bind) ^ bool(session)):
75-
raise InvalidConfig("Either `bind` or `session` have to be used, not both")
75+
raise InvalidConfigError("Either `bind` or `session` have to be used, not both")
7676
self._external_session = session
7777
if bind:
7878
self._session_handler = AsyncSessionHandler(bind)
@@ -104,7 +104,7 @@ async def get(self, identifier: PRIMARY_KEY) -> MODEL:
104104
async with self._get_session(commit=False) as session:
105105
model = await session.get(self._model, identifier)
106106
if model is None:
107-
raise ModelNotFound("No rows found for provided primary key.")
107+
raise ModelNotFoundError("No rows found for provided primary key.")
108108
return model
109109

110110
async def get_many(self, identifiers: Iterable[PRIMARY_KEY]) -> List[MODEL]:

sqlalchemy_bind_manager/_repository/base_repository.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from sqlalchemy.orm.exc import UnmappedClassError
3535
from sqlalchemy.sql import Select
3636

37-
from sqlalchemy_bind_manager.exceptions import InvalidModel, UnmappedProperty
37+
from sqlalchemy_bind_manager.exceptions import InvalidModelError, UnmappedPropertyError
3838

3939
from .common import (
4040
MODEL,
@@ -54,7 +54,7 @@ def __init__(self, model_class: Union[Type[MODEL], None] = None) -> None:
5454
if getattr(self, "_model", None) is None or not self._is_mapped_class(
5555
self._model
5656
):
57-
raise InvalidModel(
57+
raise InvalidModelError(
5858
"You need to supply a valid model class"
5959
" either in the `model_class` parameter"
6060
" or in the `_model` class property."
@@ -78,11 +78,11 @@ def _validate_mapped_property(self, property_name: str) -> None:
7878
7979
:param property_name: The name of the property to be evaluated.
8080
:type property_name: str
81-
:raises UnmappedProperty: When the property is not mapped.
81+
:raises UnmappedPropertyError: When the property is not mapped.
8282
"""
8383
m: Mapper = class_mapper(self._model)
8484
if property_name not in m.column_attrs:
85-
raise UnmappedProperty(
85+
raise UnmappedPropertyError(
8686
f"Property `{property_name}` is not mapped"
8787
f" in the ORM for model `{self._model}`"
8888
)
@@ -341,4 +341,4 @@ def _model_pk(self) -> str:
341341

342342
def _fail_if_invalid_models(self, objects: Iterable[MODEL]) -> None:
343343
if [x for x in objects if not isinstance(x, self._model)]:
344-
raise InvalidModel("Cannot handle models not belonging to this repository")
344+
raise InvalidModelError("Cannot handle models not belonging to this repository")

sqlalchemy_bind_manager/_repository/sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
from .._bind_manager import SQLAlchemyBind
3939
from .._session_handler import SessionHandler
40-
from ..exceptions import InvalidConfig, ModelNotFound
40+
from ..exceptions import InvalidConfigError, ModelNotFoundError
4141
from .base_repository import (
4242
BaseRepository,
4343
)
@@ -64,7 +64,7 @@ def __init__(
6464
) -> None:
6565
super().__init__(model_class=model_class)
6666
if not (bool(bind) ^ bool(session)):
67-
raise InvalidConfig("Either `bind` or `session` have to be used, not both")
67+
raise InvalidConfigError("Either `bind` or `session` have to be used, not both")
6868
self._external_session = session
6969
if bind:
7070
self._session_handler = SessionHandler(bind)
@@ -93,7 +93,7 @@ def get(self, identifier: PRIMARY_KEY) -> MODEL:
9393
with self._get_session(commit=False) as session:
9494
model = session.get(self._model, identifier)
9595
if model is None:
96-
raise ModelNotFound("No rows found for provided primary key.")
96+
raise ModelNotFoundError("No rows found for provided primary key.")
9797
return model
9898

9999
def get_many(self, identifiers: Iterable[PRIMARY_KEY]) -> List[MODEL]:

sqlalchemy_bind_manager/_session_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
SQLAlchemyAsyncBind,
3333
SQLAlchemyBind,
3434
)
35-
from sqlalchemy_bind_manager.exceptions import UnsupportedBind
35+
from sqlalchemy_bind_manager.exceptions import UnsupportedBindError
3636

3737

3838
class SessionHandler:
3939
scoped_session: scoped_session
4040

4141
def __init__(self, bind: SQLAlchemyBind):
4242
if not isinstance(bind, SQLAlchemyBind):
43-
raise UnsupportedBind("Bind is not an instance of SQLAlchemyBind")
43+
raise UnsupportedBindError("Bind is not an instance of SQLAlchemyBind")
4444
else:
4545
self.scoped_session = scoped_session(bind.session_class)
4646

@@ -82,7 +82,7 @@ class AsyncSessionHandler:
8282

8383
def __init__(self, bind: SQLAlchemyAsyncBind):
8484
if not isinstance(bind, SQLAlchemyAsyncBind):
85-
raise UnsupportedBind("Bind is not an instance of SQLAlchemyAsyncBind")
85+
raise UnsupportedBindError("Bind is not an instance of SQLAlchemyAsyncBind")
8686
else:
8787
self.scoped_session = async_scoped_session(
8888
bind.session_class, asyncio.current_task

sqlalchemy_bind_manager/_unit_of_work/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
AsyncSessionHandler,
3131
SessionHandler,
3232
)
33-
from sqlalchemy_bind_manager.exceptions import RepositoryNotFound
33+
from sqlalchemy_bind_manager.exceptions import RepositoryNotFoundError
3434
from sqlalchemy_bind_manager.repository import (
3535
SQLAlchemyAsyncRepository,
3636
SQLAlchemyRepository,
@@ -67,7 +67,7 @@ def repository(self, name: str) -> REPOSITORY:
6767
try:
6868
return self._repositories[name]
6969
except KeyError:
70-
raise RepositoryNotFound(
70+
raise RepositoryNotFoundError(
7171
"The repository has not been initialised in this unit of work"
7272
)
7373

sqlalchemy_bind_manager/exceptions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@
1919
# DEALINGS IN THE SOFTWARE.
2020

2121

22-
class NotInitializedBind(Exception):
22+
class NotInitializedBindError(Exception):
2323
pass
2424

2525

26-
class UnsupportedBind(Exception):
26+
class UnsupportedBindError(Exception):
2727
pass
2828

2929

30-
class InvalidConfig(Exception):
30+
class InvalidConfigError(Exception):
3131
pass
3232

3333

34-
class ModelNotFound(Exception):
34+
class ModelNotFoundError(Exception):
3535
pass
3636

3737

38-
class InvalidModel(Exception):
38+
class InvalidModelError(Exception):
3939
pass
4040

4141

42-
class UnmappedProperty(Exception):
42+
class UnmappedPropertyError(Exception):
4343
pass
4444

4545

46-
class SessionNotFound(Exception):
46+
class SessionNotFoundError(Exception):
4747
pass
4848

4949

50-
class RepositoryNotFound(Exception):
50+
class RepositoryNotFoundError(Exception):
5151
pass

sqlalchemy_bind_manager/protocols.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def get(self, identifier: PRIMARY_KEY) -> MODEL:
6565
6666
:param identifier: The primary key
6767
:return: A model instance
68-
:raises ModelNotFound: No model has been found using the primary key
68+
:raises ModelNotFoundError: No model has been found using the primary key
6969
"""
7070
...
7171

@@ -221,7 +221,7 @@ def get(self, identifier: PRIMARY_KEY) -> MODEL:
221221
222222
:param identifier: The primary key
223223
:return: A model instance
224-
:raises ModelNotFound: No model has been found using the primary key
224+
:raises ModelNotFoundError: No model has been found using the primary key
225225
"""
226226
...
227227

tests/repository/test_find.py

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

3-
from sqlalchemy_bind_manager.exceptions import UnmappedProperty
3+
from sqlalchemy_bind_manager.exceptions import UnmappedPropertyError
44
from sqlalchemy_bind_manager.repository import SortDirection
55

66

@@ -44,7 +44,7 @@ async def test_find_filtered_fails_if_invalid_filter(
4444
repository_class, model_class, sa_bind, sync_async_wrapper
4545
):
4646
repo = repository_class(bind=sa_bind, model_class=model_class)
47-
with pytest.raises(UnmappedProperty):
47+
with pytest.raises(UnmappedPropertyError):
4848
await sync_async_wrapper(repo.find(search_params={"somename": "Someone"}))
4949

5050

@@ -79,7 +79,7 @@ async def test_find_ordered_fails_if_invalid_column(
7979
repository_class, model_class, sa_bind, sync_async_wrapper
8080
):
8181
repo = repository_class(bind=sa_bind, model_class=model_class)
82-
with pytest.raises(UnmappedProperty):
82+
with pytest.raises(UnmappedPropertyError):
8383
await repo.find(order_by=("unexisting",))
84-
with pytest.raises(UnmappedProperty):
84+
with pytest.raises(UnmappedPropertyError):
8585
await repo.find(order_by=(("unexisting", SortDirection.DESC),))
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from sqlalchemy_bind_manager.exceptions import InvalidModel
3+
from sqlalchemy_bind_manager.exceptions import InvalidModelError
44

55

66
async def test_fails_when_saving_models_not_belonging_to_repository(
@@ -10,14 +10,14 @@ async def test_fails_when_saving_models_not_belonging_to_repository(
1010

1111
invalid_model = model_classes[1](name="A Child")
1212

13-
with pytest.raises(InvalidModel):
13+
with pytest.raises(InvalidModelError):
1414
await sync_async_wrapper(repo.save(invalid_model))
1515

16-
with pytest.raises(InvalidModel):
16+
with pytest.raises(InvalidModelError):
1717
await sync_async_wrapper(repo.save_many([invalid_model]))
1818

19-
with pytest.raises(InvalidModel):
19+
with pytest.raises(InvalidModelError):
2020
await sync_async_wrapper(repo.delete(invalid_model))
2121

22-
with pytest.raises(InvalidModel):
22+
with pytest.raises(InvalidModelError):
2323
await sync_async_wrapper(repo.delete_many([invalid_model]))

0 commit comments

Comments
 (0)