# tests/test_featured_reason.py """T6: 首推理由行(pick_why + DAILY_FEATURED_REASON 开关)测试。""" from __future__ import annotations import unittest from unittest import mock import daily.format_wecom as fw def _build(pick_why: str) -> str: return fw.build_wecom_report( date_str="2026-07-18", time_str="08:50 (UTC+8)", updated="2026-07-18", highlights=[], theme_line="**今日主题**:测试", ai_news=None, cn_ai_news=None, merged_ai_news=None, merged_tech_ai_news=None, trending=[], hot=[], repos=[], emerging=[], topic_name="t", topic_repos=[], pick_command="npx skills add src/alpha", pick_why=pick_why, pick_title="alpha", pick_url="https://x/a", include_boards=False, ) class FeaturedReasonTests(unittest.TestCase): def test_reason_shown_when_present_and_enabled(self): with mock.patch.object(fw, "env_bool", return_value=True): md = _build("昨日 star 增速第一") self.assertIn("> 昨日 star 增速第一", md) def test_reason_hidden_when_switch_off(self): with mock.patch.object(fw, "env_bool", return_value=False): md = _build("昨日 star 增速第一") self.assertNotIn("> 昨日 star 增速第一", md) def test_reason_omitted_when_empty(self): with mock.patch.object(fw, "env_bool", return_value=True): md = _build("") self.assertIn("今日首推", md) self.assertNotIn("> \n", md) if __name__ == "__main__": unittest.main()