"""market_intelligence 뉴스 감성 섹션 계약 테스트 (인자 불일치 TypeError 회귀).""" import asyncio import pytest from app.api.endpoints import market_intelligence as mi from app.services import news_sentiment as ns def _run(coro): return asyncio.new_event_loop().run_until_complete(coro) def _boom(*a, **k): raise AssertionError("잘못된 함수 호출") def test_market_score_wrapped_in_dict(monkeypatch): async def market(): return 0.25 monkeypatch.setattr(ns, "get_market_news_score", market) monkeypatch.setattr(ns, "get_stock_news_score", _boom) res = _run(mi._get_news_sentiment()) assert res["market_score"] == 0.25 assert res["reason"] is None assert {"top_positive", "top_negative"} <= set(res) def test_stock_code_uses_stock_score(monkeypatch): seen = {} async def stock(code): seen["code"] = code return -0.4 monkeypatch.setattr(ns, "get_stock_news_score", stock) monkeypatch.setattr(ns, "get_market_news_score", _boom) res = _run(mi._get_news_sentiment(stock_code="005930")) assert seen["code"] == "005930" assert res["market_score"] == -0.4 def test_endpoint_contract(monkeypatch): async def market(): return 0.1 monkeypatch.setattr(ns, "get_market_news_score", market) res = _run(mi.get_market_news(stock_code=None)) assert res["market_score"] == 0.1 assert "timestamp" in res and res["stock_code"] is None assert not str(res.get("reason") or "").startswith("조회 실패")