From c14f8d4b5e240ac8851e203d2eda6b4f70683b26 Mon Sep 17 00:00:00 2001 From: Denis Anikin Date: Tue, 26 Sep 2023 04:41:55 +0300 Subject: [PATCH] All fixed? --- .gitignore | 3 +++ Makefile | 2 +- pyproject.toml | 2 +- scripts/__main__.py | 6 +----- scripts/_helpers.py | 11 ++--------- tests/test_dict_views.py | 15 +++++---------- tests/test_misc.py | 3 ++- tests/test_spell_views.py | 7 +++---- tests/test_various_views.py | 1 + whole_app/dictionaries/file.py | 6 +----- whole_app/settings.py | 4 +--- whole_app/spell.py | 4 +--- 12 files changed, 22 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index 2dc53ca..9efd968 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. .idea/ + +# More various +.DS_Store diff --git a/Makefile b/Makefile index aa5940e..6632985 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ test-in-docker: docker run -t spellcheck-microservice bash -c "COVERAGE_FILE=/tmp/junk.coverage pytest . -n3" lint: - ruff . + ruff . --no-fix mypy . vulture whole_app --min-confidence 100 black . --check diff --git a/pyproject.toml b/pyproject.toml index f7f79e7..4410f35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ line-length = 120 line-length = 120 fix = true select = ["ALL"] -ignore = ["D1", "D203", "D213", "FA102", "I", "ANN101"] +ignore = ["D1", "D203", "D213", "FA102", "ANN101"] [tool.ruff.isort] lines-after-imports = 2 diff --git a/scripts/__main__.py b/scripts/__main__.py index 0cadbb2..997e7d6 100755 --- a/scripts/__main__.py +++ b/scripts/__main__.py @@ -42,11 +42,7 @@ def _update_readme() -> None: "" if "exclusiveMinimum" not in props else f", allowed values from `{props['exclusiveMinimum'] + 1}`" - + ( - f"to `{props['exclusiveMaximum'] - 1}`" - if "exclusiveMaximum" in props - else "" - ) + + (f"to `{props['exclusiveMaximum'] - 1}`" if "exclusiveMaximum" in props else "") ) pack_of_readme_lines.append( f'`{settings_env_key}` {props["description"].rstrip(".")}. ' diff --git a/scripts/_helpers.py b/scripts/_helpers.py index 0304bd0..88e65dd 100644 --- a/scripts/_helpers.py +++ b/scripts/_helpers.py @@ -11,18 +11,11 @@ def parse_last_git_tag() -> str: git_tags_list: typing.Final = shlex.split( "git rev-list --tags --max-count=1", ) - last_tag_hash: typing.Final = ( - subprocess.check_output(git_tags_list).strip().decode() # noqa: S603 - ) + last_tag_hash: typing.Final = subprocess.check_output(git_tags_list).strip().decode() # noqa: S603 git_tag_description: typing.Final = shlex.split( f"git describe --tags {last_tag_hash}", ) - return ( - subprocess.check_output(git_tag_description) # noqa: S603 - .strip() - .decode() - .lstrip("v") - ) + return subprocess.check_output(git_tag_description).strip().decode().lstrip("v") # noqa: S603 return last_tag_from_environment.lstrip("v") diff --git a/tests/test_dict_views.py b/tests/test_dict_views.py index 87c20c7..2fa2d58 100644 --- a/tests/test_dict_views.py +++ b/tests/test_dict_views.py @@ -35,10 +35,8 @@ def test_add_to_dict( ) -> None: fake_user_name: typing.Final = faker_obj.user_name() fake_exc_word: typing.Final = faker_obj.word() - path_to_dict_file: typing.Final = ( - SETTINGS.dictionaries_path.joinpath( # pylint: disable=no-member - fake_user_name, - ) + path_to_dict_file: typing.Final = SETTINGS.dictionaries_path.joinpath( # pylint: disable=no-member + fake_user_name, ) server_response = app_client.post( DICT_ENDPOINT, @@ -60,10 +58,8 @@ def test_remove_from_user_dict( ) -> None: fake_exc_word: typing.Final = faker_obj.word() fake_user_name: typing.Final = faker_obj.user_name() - path_to_dict_file: typing.Final = ( - SETTINGS.dictionaries_path.joinpath( # pylint: disable=no-member - fake_user_name, - ) + path_to_dict_file: typing.Final = SETTINGS.dictionaries_path.joinpath( # pylint: disable=no-member + fake_user_name, ) path_to_dict_file.touch() path_to_dict_file.write_text(fake_exc_word) @@ -141,8 +137,7 @@ def test_wrong_api_key(self: "TestVarious") -> None: exception_word="test", ).dict(), headers={ - SETTINGS.api_key_header_name: SETTINGS.api_key - + "wrongTrashKekJunk --- 5000", + SETTINGS.api_key_header_name: SETTINGS.api_key + "wrongTrashKekJunk --- 5000", }, ) assert server_response.status_code == 401 diff --git a/tests/test_misc.py b/tests/test_misc.py index 9ce252c..349a3af 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3,14 +3,15 @@ import importlib import os import runpy -from typing import TYPE_CHECKING import typing +from typing import TYPE_CHECKING from fastapi.testclient import TestClient from whole_app import views from whole_app.settings import SETTINGS, SettingsOfMicroservice + if TYPE_CHECKING: import faker diff --git a/tests/test_spell_views.py b/tests/test_spell_views.py index 61dfae9..93f7eb2 100644 --- a/tests/test_spell_views.py +++ b/tests/test_spell_views.py @@ -1,19 +1,18 @@ # pylint: disable=redefined-outer-name -"""Basic test for views.""" import random import typing import pytest +from requests.models import Response as RequestsResponse +from ._fixtures import BAD_PAYLOAD from whole_app import models from whole_app.settings import SETTINGS, StorageProviders -from ._fixtures import BAD_PAYLOAD -from requests.models import Response as RequestsResponse if typing.TYPE_CHECKING: - from fastapi.testclient import TestClient import faker + from fastapi.testclient import TestClient RUSSIAN_LETTERS: typing.Final = "абвгдежзийклмнопрстуфхцчшщъыьэюяё" diff --git a/tests/test_various_views.py b/tests/test_various_views.py index 91e3898..a37ee10 100644 --- a/tests/test_various_views.py +++ b/tests/test_various_views.py @@ -3,6 +3,7 @@ from whole_app.settings import SETTINGS + if typing.TYPE_CHECKING: from fastapi.testclient import TestClient diff --git a/whole_app/dictionaries/file.py b/whole_app/dictionaries/file.py index 3cc4a2d..f91ee66 100644 --- a/whole_app/dictionaries/file.py +++ b/whole_app/dictionaries/file.py @@ -36,9 +36,5 @@ async def remove_record(self: "FileProvider", exception_word: str) -> None: async def fetch_records(self: "FileProvider") -> list[str]: if await self._user_dict_path.exists(): - return [ - one_line.strip() - for one_line in (await self._user_dict_path.read_text()).split("\n") - if one_line - ] + return [one_line.strip() for one_line in (await self._user_dict_path.read_text()).split("\n") if one_line] return [] diff --git a/whole_app/settings.py b/whole_app/settings.py index 854d5ee..859c52b 100644 --- a/whole_app/settings.py +++ b/whole_app/settings.py @@ -8,9 +8,7 @@ from pydantic_settings import BaseSettings -PATH_TO_PYPROJECT: typing.Final = ( - pathlib.Path(__file__).parent.parent / "pyproject.toml" -) +PATH_TO_PYPROJECT: typing.Final = pathlib.Path(__file__).parent.parent / "pyproject.toml" AvailableLanguagesType = typing.Literal[ "ru_RU", "en_US", diff --git a/whole_app/spell.py b/whole_app/spell.py index 3d6f686..77e87ed 100644 --- a/whole_app/spell.py +++ b/whole_app/spell.py @@ -39,9 +39,7 @@ def get_memorized_suggestions(word_spellcheck_result: SpellChecker) -> list[str] misspelled_suggestions = word_spellcheck_result.suggest() _MISSPELED_CACHE[word_spellcheck_result.word] = misspelled_suggestions return ( - misspelled_suggestions[: SETTINGS.max_suggestions] - if SETTINGS.max_suggestions - else misspelled_suggestions + misspelled_suggestions[: SETTINGS.max_suggestions] if SETTINGS.max_suggestions else misspelled_suggestions ) def run_check(self: "SpellCheckService") -> list[models.OneCorrection]: