diff --git a/tests/test_commands_pg.py b/tests/test_commands_pg.py index c2c8457..ff5edbe 100644 --- a/tests/test_commands_pg.py +++ b/tests/test_commands_pg.py @@ -73,14 +73,15 @@ class TestPgCommand: @pytest.mark.asyncio async def test_pg_empty_current_condition(self): - """current_condition пустой список — код выбрасывает IndexError (баг в коде).""" + """current_condition пустой список — graceful fallback.""" cog = self._make_cog() ctx = self._make_ctx() weather = {"current_condition": []} with patch("commands.pg.fetch_weather", new=AsyncMock(return_value=weather)): - with pytest.raises(IndexError): - await cog.pg.callback(cog, ctx) + await cog.pg.callback(cog, ctx) + ctx.send.assert_called_once() + assert "Не удалось получить данные о погоде" in ctx.send.call_args[0][0] @pytest.mark.asyncio async def test_pg_current_condition_none(self): diff --git a/utils/pogoda.py b/utils/pogoda.py index baae06a..880485c 100644 --- a/utils/pogoda.py +++ b/utils/pogoda.py @@ -155,7 +155,10 @@ def format_weather_data_for_console(data): """ if data is None: return None - current = data.get("current_condition", [{}])[0] + current_condition_list = data.get("current_condition", []) + if not current_condition_list: + return None + current = current_condition_list[0] if not current: return None