test_config.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Config tests
  5. """
  6. import os
  7. from data_modules import config as config_module
  8. from data_modules.config import DataModulesConfig, get_config, set_project_root
  9. def test_config_paths_and_defaults(tmp_path):
  10. cfg = DataModulesConfig.from_project_root(tmp_path)
  11. assert cfg.project_root == tmp_path
  12. assert cfg.webnovel_dir.name == ".webnovel"
  13. assert cfg.state_file.name == "state.json"
  14. assert cfg.index_db.name == "index.db"
  15. assert cfg.rag_db.name == "rag.db"
  16. assert cfg.vector_db.name == "vectors.db"
  17. cfg.ensure_dirs()
  18. assert cfg.webnovel_dir.exists()
  19. def test_get_config_and_set_project_root(tmp_path):
  20. set_project_root(tmp_path)
  21. cfg = get_config()
  22. assert cfg.project_root == tmp_path
  23. def test_load_dotenv(monkeypatch, tmp_path):
  24. # prepare .env
  25. env_path = tmp_path / ".env"
  26. env_path.write_text("EMBED_BASE_URL=https://example.com\n", encoding="utf-8")
  27. monkeypatch.chdir(tmp_path)
  28. monkeypatch.delenv("EMBED_BASE_URL", raising=False)
  29. # call loader explicitly
  30. config_module._load_dotenv()
  31. assert os.environ.get("EMBED_BASE_URL") == "https://example.com"