Refactor AI daily report pipeline
This commit is contained in:
39
tests/test_env_loading.py
Normal file
39
tests/test_env_loading.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import importlib.util
|
||||
import os
|
||||
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 EnvLoadingTests(unittest.TestCase):
|
||||
def test_project_env_is_loaded_and_process_env_wins(self):
|
||||
module = load_pipeline_module()
|
||||
env_text = "LLM_MODEL=file-model\nLLM_BASE_URL=https://file.example/v1\n"
|
||||
|
||||
with patch.object(module.Path, "home", return_value=ROOT / "missing-home"):
|
||||
with patch.dict(os.environ, {"LLM_MODEL": "process-model"}, clear=False):
|
||||
with patch.object(module, "PROJECT_ENV_PATH", ROOT / ".env.test"):
|
||||
(ROOT / ".env.test").write_text(env_text, encoding="utf-8")
|
||||
try:
|
||||
env = module.load_env()
|
||||
finally:
|
||||
(ROOT / ".env.test").unlink(missing_ok=True)
|
||||
|
||||
self.assertEqual(env["LLM_BASE_URL"], "https://file.example/v1")
|
||||
self.assertEqual(env["LLM_MODEL"], "process-model")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user