fix: format_articles(None) возвращает graceful fallback вместо TypeError
This commit is contained in:
parent
f825be866b
commit
1ab3205333
@ -125,9 +125,10 @@ class TestFormatArticles:
|
||||
assert len(result) == 1
|
||||
|
||||
def test_format_articles_none(self) -> None:
|
||||
"""None должен вызвать TypeError (articles[:5] на None)."""
|
||||
with pytest.raises(TypeError):
|
||||
format_articles(None, "Заголовок", "https://habr.com/feed")
|
||||
"""None должен вернуть graceful fallback вместо TypeError."""
|
||||
result = format_articles(None, "Заголовок", "https://habr.com/feed")
|
||||
assert len(result) == 2
|
||||
assert "Не удалось загрузить статьи." in result[1]
|
||||
|
||||
def test_format_articles_single_article(self) -> None:
|
||||
"""Одна статья должна быть корректно отформатирована."""
|
||||
|
||||
@ -135,6 +135,8 @@ def truncate_message(text: str, max_len: int = 2000) -> str:
|
||||
|
||||
def format_articles(articles: list[dict], title: str, link: str) -> list[str]:
|
||||
"""Сформировать список строк для вывода статей/постов."""
|
||||
if articles is None:
|
||||
return [f"{title}\n<{link}>", "Не удалось загрузить статьи."]
|
||||
lines = [f"{title}\n<{link}>"]
|
||||
for i, article in enumerate(articles[:5], 1):
|
||||
date_str = _parse_date(article["pub_date"])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user