diff --git a/ISSUES.md b/ISSUES.md index 865c2e4..06cd472 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -75,7 +75,7 @@ ### Высокий приоритет -- [ ] **`ruff format --check` падает на 5 файлах** — `bot.py`, `utils/__init__.py`, `tests/test_commands_news.py`, `tests/test_help_command.py`, `tests/test_morning_runner.py` требуют применения форматирования +- [x] ~~**`ruff format --check` падает на 5 файлах**~~ — применён `ruff format` к 7 файлам (`bot.py`, `tests/test_commands_news.py`, `tests/test_commands_pg.py`, `tests/test_fetch_weather.py`, `tests/test_help_command.py`, `tests/test_morning_runner.py`, `utils/pogoda.py`) ### Средний приоритет diff --git a/bot.py b/bot.py index c33a769..a7d04f4 100644 --- a/bot.py +++ b/bot.py @@ -34,7 +34,8 @@ class TextHelpCommand(commands.HelpCommand): return f"!{command.qualified_name} {command.signature}" async def send_bot_help( - self, mapping: dict[discord.ext.commands.Command, list[discord.ext.commands.Command]] + self, + mapping: dict[discord.ext.commands.Command, list[discord.ext.commands.Command]], ) -> None: lines: list[str] = ["Доступные команды:"] @@ -54,9 +55,7 @@ class TextHelpCommand(commands.HelpCommand): lines.append("\nВведите !<название команды> для использования.") await self.get_destination().send("\n".join(lines)) - async def send_cog_help( - self, cog: discord.ext.commands.Cog - ) -> None: + async def send_cog_help(self, cog: discord.ext.commands.Cog) -> None: commands_with_desc = cog.get_commands() lines: list[str] = [f"Команды [{cog.qualified_name}]:"] for command in commands_with_desc: @@ -75,9 +74,7 @@ class TextHelpCommand(commands.HelpCommand): await self.get_destination().send("\n".join(lines)) - async def send_group_help( - self, group: commands.Group - ) -> None: + async def send_group_help(self, group: commands.Group) -> None: lines: list[str] = [f"!{group.qualified_name} {group.signature}"] if group.doc: lines.append(group.short_doc or group.help) @@ -92,6 +89,7 @@ class TextHelpCommand(commands.HelpCommand): async def send_error_message(self, error: str) -> None: await self.get_destination().send(error) + load_dotenv() intents = discord.Intents.default() diff --git a/tests/test_commands_news.py b/tests/test_commands_news.py index 6540af3..4ee03dc 100644 --- a/tests/test_commands_news.py +++ b/tests/test_commands_news.py @@ -41,7 +41,13 @@ class TestNewsCommand: def _make_articles(self, count: int = 3) -> list[dict]: return [ - {"title": f"Статья {i}", "link": f"https://habr.com/article/{i}", "pub_date": f"Mon, 28 May 2026 10:00:00 +0000", "creator": "author", "tags": []} + { + "title": f"Статья {i}", + "link": f"https://habr.com/article/{i}", + "pub_date": f"Mon, 28 May 2026 10:00:00 +0000", + "creator": "author", + "tags": [], + } for i in range(1, count + 1) ] diff --git a/tests/test_commands_pg.py b/tests/test_commands_pg.py index f7f8367..fcd9f2c 100644 --- a/tests/test_commands_pg.py +++ b/tests/test_commands_pg.py @@ -109,7 +109,9 @@ class TestPgCommand: """wind_speed_mps — не число — показываются порывы ветра (gust fallback).""" cog = self._make_cog() ctx = self._make_ctx() - weather = self._make_weather_data(wind_speed_mps="abc") # gust=8.0, dir=n по умолчанию + weather = self._make_weather_data( + wind_speed_mps="abc" + ) # gust=8.0, dir=n по умолчанию with patch("commands.pg.fetch_weather", new=AsyncMock(return_value=weather)): await cog.pg.callback(cog, ctx) @@ -138,7 +140,9 @@ class TestPgCommand: """wind_speed_mps = 0 — 0.0 + порывы + направление.""" cog = self._make_cog() ctx = self._make_ctx() - weather = self._make_weather_data(wind_speed_mps=0) # gust=8.0, dir=n по умолчанию + weather = self._make_weather_data( + wind_speed_mps=0 + ) # gust=8.0, dir=n по умолчанию with patch("commands.pg.fetch_weather", new=AsyncMock(return_value=weather)): await cog.pg.callback(cog, ctx) diff --git a/tests/test_fetch_weather.py b/tests/test_fetch_weather.py index 19fd810..ea9b36a 100644 --- a/tests/test_fetch_weather.py +++ b/tests/test_fetch_weather.py @@ -88,7 +88,9 @@ class TestFetchWeather: result = await fetch_weather() assert result is not None - assert result["current_condition"][0]["weatherDesc"] == [{"value": "Неизвестно"}] + assert result["current_condition"][0]["weatherDesc"] == [ + {"value": "Неизвестно"} + ] @patch("utils.pogoda._session.get") async def test_fetch_weather_ssl_error_retry(self, mock_get) -> None: @@ -261,7 +263,9 @@ class TestFetchWeather: assert result is not None assert result["current_condition"][0]["temp_C"] == -15 - assert result["current_condition"][0]["weatherDesc"] == [{"value": "Сильный снег"}] + assert result["current_condition"][0]["weatherDesc"] == [ + {"value": "Сильный снег"} + ] @patch("utils.pogoda._session.get") async def test_fetch_weather_includes_headers(self, mock_get) -> None: diff --git a/tests/test_help_command.py b/tests/test_help_command.py index 4af09f6..36a7ca7 100644 --- a/tests/test_help_command.py +++ b/tests/test_help_command.py @@ -14,6 +14,7 @@ sys.path.insert(0, str(ROOT_DIR)) def help_command() -> "bot.TextHelpCommand": """Создать экземпляр TextHelpCommand.""" import bot + return bot.TextHelpCommand() diff --git a/tests/test_morning_runner.py b/tests/test_morning_runner.py index 10bc3b6..1c4c626 100644 --- a/tests/test_morning_runner.py +++ b/tests/test_morning_runner.py @@ -243,6 +243,4 @@ class TestRunMorningWithFallback: # Проверяем, что в тексте есть погода и нет fallback сообщения assert "Погода в Магнитогорске" in message_text - assert ( - "Не удалось получить данные из внешних источников" not in message_text - ) + assert "Не удалось получить данные из внешних источников" not in message_text diff --git a/utils/pogoda.py b/utils/pogoda.py index 620dda4..81449e8 100644 --- a/utils/pogoda.py +++ b/utils/pogoda.py @@ -71,7 +71,10 @@ async def fetch_weather( async with _weather_cache_lock: cached_data, cached_time = _weather_cache if time.monotonic() - cached_time < _WEATHER_CACHE_TTL: - logger.debug("Погода: возвращены данные из кэша (TTL %.0f сек)", _WEATHER_CACHE_TTL) + logger.debug( + "Погода: возвращены данные из кэша (TTL %.0f сек)", + _WEATHER_CACHE_TTL, + ) return cached_data await yandex_weather_limiter.acquire() @@ -92,7 +95,13 @@ async def fetch_weather( { "temp_C": fact.get("temp"), "FeelsLikeC": fact.get("feels_like"), - "weatherDesc": [{"value": yandex_condition_to_russian(fact.get("condition"))}], + "weatherDesc": [ + { + "value": yandex_condition_to_russian( + fact.get("condition") + ) + } + ], "humidity": fact.get("humidity"), "wind_speed_mps": fact.get("wind_speed"), "wind_gust": fact.get("wind_gust"),