Skip to content

Commit

Permalink
Fixed autopep8 in pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpro2022 committed Dec 10, 2023
1 parent 2a11ecf commit a8f7077
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 31 deletions.
17 changes: 5 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ repos:
args: [--py310-plus]

# Форматирует код под PEP8
#- repo: https://github.com/pre-commit/mirrors-autopep8
# rev: v2.0.1
# hooks:
# - id: autopep8
# args: [--max-line-length=120, --in-place]
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.4
hooks:
- id: autopep8
args: [--max-line-length=120, --in-place]

# Сканер стилистических ошибок, нарушающие договоренности PEP8
- repo: https://github.com/PyCQA/flake8
Expand All @@ -40,10 +40,3 @@ repos:
- id: flake8
exclude: "__init__.py"
args: ["--ignore=F821,F403,F405"]

# Проверка статических типов с помощью mypy
#- repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.991
# hooks:
# - id: mypy
# exclude: 'migrations'
6 changes: 4 additions & 2 deletions app/core/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ def get_jwt_strategy() -> JWTStrategy:


# Create superuseruser programmatically
async def create_user(async_generator: Generator, email: EmailStr, password: str, is_superuser: bool = False) -> User:
async def create_user(
async_session_generator: Generator, email: EmailStr, password: str, is_superuser: bool = False
) -> User:
try:
async with (asynccontextmanager(async_generator)() as session,
async with (asynccontextmanager(async_session_generator)() as session,
asynccontextmanager(get_user_db)(session) as user_db,
asynccontextmanager(get_user_manager)(user_db) as user_manager):
user = await user_manager.create(UserCreate(email=email, password=password, is_superuser=is_superuser))
Expand Down
1 change: 0 additions & 1 deletion tests/base_services/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Model(Base):
optional_field: Mapped[dt | None]



class SchemaCreate(BaseModel):
title: str = Field(max_length=MAX_LEN)
description: str = Field(max_length=MAX_LEN)
Expand Down
5 changes: 3 additions & 2 deletions tests/base_services/test_base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ async def test_method_raises_exception_not_found(self, method_name) -> None:

@pytest_mark_anyio
@pytest.mark.parametrize('method_name',
('set_cache_on_create', 'set_cache_on_update', 'set_cache_on_delete',
'create', 'update', 'delete'))
('set_cache_on_create', 'set_cache_on_update',
'set_cache_on_delete', 'create', 'update', 'delete')
)
async def test_method_raises_exception_not_implemented(self, method_name, get_obj_in_db) -> None:
pk = 1
payload = self.update_schema(**self.update_payload)
Expand Down
5 changes: 3 additions & 2 deletions tests/base_services/test_db_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_not_implemented_method_raises_exception(self, method_name: str, args: t
@pytest_mark_anyio
@pytest.mark.parametrize('method_name', ('update', 'delete'))
async def test_update_delete_methods_raise_not_found_exceptions(self, method_name: str) -> None:
expected_msg=self.msg_not_found
expected_msg = self.msg_not_found
await self._update_delete_raise_exceptions(method_name, HTTPException, expected_msg, not_found=True)

@pytest_mark_anyio
Expand All @@ -185,4 +185,5 @@ async def _update_delete_raise_exceptions(self, method_name, exc_type, expected_
await func()
with pytest.raises(exc_type) as exc_info:
await method(*args, user=user)
check_exception_info_not_found(exc_info, self.msg_not_found) if not_found else check_exception_info(exc_info, expected_msg)
(check_exception_info_not_found(exc_info, self.msg_not_found) if not_found else
check_exception_info(exc_info, expected_msg))
2 changes: 1 addition & 1 deletion tests/fixtures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

# Payloads
POST_PAYLOAD = {'title': 'POST New post title.', 'content': 'POST New post content.'}
PUT_PAYLOAD = {'title': 'update for title.', 'content': 'update for content.'}
PUT_PAYLOAD = {'title': 'update for title.', 'content': 'update for content.'}
3 changes: 2 additions & 1 deletion tests/fixtures/endpoints_testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __dummy_func(*args, **kwargs) -> str:
def assert_status(response: Response, expected_status_code: int | tuple[int, ...]) -> None:
if isinstance(expected_status_code, int):
expected_status_code = (expected_status_code,)
assert response.status_code in expected_status_code, (response.status_code, expected_status_code, response.headers, response.text)
assert response.status_code in expected_status_code, (response.status_code, expected_status_code,
response.headers, response.text)


def assert_msg(response: Response, expected_msg: str | None) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def test_get_data_from_tickers(event_loop):
assert name in CURRENCIES
assert isinstance(price, float)
assert isinstance(timestamp, int)
res = ((dt.now() - timedelta(seconds=seconds)).timestamp()
< timestamp <
res = ((dt.now() - timedelta(seconds=seconds)).timestamp() <
timestamp <
(dt.now() + timedelta(seconds=seconds)).timestamp())
assert res
2 changes: 1 addition & 1 deletion tests/integration_tests/test_endpoints_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
((DELETE, PATCH, POST, PUT), LIKE_ENDPOINT, ID),
((DELETE, PATCH, POST, PUT), DISLIKE_ENDPOINT, ID),
))
async def test_not_allowed_methods(async_client, admin_user, not_allowed_methods, endpoint, post_id ):
async def test_not_allowed_methods(async_client, admin_user, not_allowed_methods, endpoint, post_id):
for method in not_allowed_methods:
await assert_response(HTTPStatus.METHOD_NOT_ALLOWED, async_client, method, endpoint, path_param=post_id)

Expand Down
3 changes: 2 additions & 1 deletion tests/unit_tests/test_endpoint_testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_get_invalid() -> None:


@pytest.mark.parametrize('item, expected_result', (
('', ''), (' ', ''), ('/', ''), ('///////////', ''), (f'/{SLASHLESS}/', SLASHLESS), (f'///{SLASHLESS}///', SLASHLESS),
('', ''), (' ', ''), ('/', ''), ('///////////', ''),
(f'/{SLASHLESS}/', SLASHLESS), (f'///{SLASHLESS}///', SLASHLESS),
))
def test_strip_slashes(item: str, expected_result: str) -> None:
assert lib.strip_slashes(item) == expected_result.lower()
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
POST_MODEL_FIELDS = ('id', 'title', 'content', 'created', 'updated', 'likes', 'dislikes', 'author_id', 'author')
POST_SAVE_DATA = {'title': 'Another New post title.', 'content': 'POST New post content.', 'author_id': 1}


class BaseTest(Base):
pass

Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/test_post_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def test_create_posts_fixture(self, posts) -> None:
def test_messages(self) -> None:
def get_class_vars_consts(class_):
return [attr for attr in class_.__dict__ if (
getattr(class_, attr) is not None
and not isinstance(getattr(class_, attr), Callable)
and not attr.startswith('__')
getattr(class_, attr) is not None and
not isinstance(getattr(class_, attr), Callable) and
not attr.startswith('__')
)]
test_attrs = get_class_vars_consts(self.__class__)
post_attrs = get_class_vars_consts(PostRepository)
Expand Down Expand Up @@ -97,4 +97,4 @@ def check_likes_dislikes(one: int, zero: int):
for post in author_posts:
obj: Post = await self.repo.like_dislike_post(post.id, auth_user, like)
args = (obj.likes, obj.dislikes) if like else (obj.dislikes, obj.likes)
check_likes_dislikes(*args)
check_likes_dislikes(*args)
1 change: 1 addition & 0 deletions tests/unit_tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

USER_CREDS = (settings.admin_email, settings.admin_password)


def check_user(user: User, is_superuser: bool = True) -> None:
assert user.email == settings.admin_email
assert user.hashed_password
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
VALID_CONTENT_ARGS = ('password', 'email')

INVALID_LENGTH_MSG = f'Пароль должен быть длиной не менее {settings.password_length} символов.'
INVALID_LENGTH_ARGS = ('a'*(settings.password_length-1),)
VALID_LENGTH_ARGS = ('a'*(settings.password_length),)
INVALID_LENGTH_ARGS = ('a' * (settings.password_length - 1),)
VALID_LENGTH_ARGS = ('a' * (settings.password_length),)


@pytest.mark.parametrize('method, valid_args, invalid_args, error_msg', (
Expand Down

0 comments on commit a8f7077

Please sign in to comment.