58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
import importlib.util
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPT = ROOT / "script" / "ai_daily_blog_pipeline.py"
|
|
|
|
|
|
def load_pipeline_module():
|
|
spec = importlib.util.spec_from_file_location("ai_daily_blog_pipeline", SCRIPT)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
class LegacyScriptDelegationTests(unittest.TestCase):
|
|
def test_main_delegates_to_new_pipeline_by_default(self):
|
|
module = load_pipeline_module()
|
|
calls = []
|
|
|
|
def fake_run_daily_report(**kwargs):
|
|
calls.append(kwargs)
|
|
return {"reports": {"stage8": {"status": "ok"}}}
|
|
|
|
with patch.object(module, "load_env", return_value={"AI_DAILY_DRY_RUN": "1"}):
|
|
with patch("ai_daily_report.runner.run_daily_report", side_effect=fake_run_daily_report):
|
|
module.main()
|
|
|
|
self.assertEqual(len(calls), 1)
|
|
self.assertEqual(calls[0]["mode"], "dry-run")
|
|
self.assertEqual(calls[0]["source_mode"], "live")
|
|
self.assertEqual(calls[0]["llm_mode"], "live")
|
|
|
|
def test_main_allows_mock_modes_for_local_test(self):
|
|
module = load_pipeline_module()
|
|
calls = []
|
|
|
|
def fake_run_daily_report(**kwargs):
|
|
calls.append(kwargs)
|
|
return {"reports": {"stage8": {"status": "ok"}}}
|
|
|
|
with patch.object(
|
|
module,
|
|
"load_env",
|
|
return_value={"AI_DAILY_DRY_RUN": "1", "AI_DAILY_SOURCE_MODE": "mock", "AI_DAILY_LLM_MODE": "mock"},
|
|
):
|
|
with patch("ai_daily_report.runner.run_daily_report", side_effect=fake_run_daily_report):
|
|
module.main()
|
|
|
|
self.assertEqual(calls[0]["source_mode"], "mock")
|
|
self.assertEqual(calls[0]["llm_mode"], "mock")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|