Make tests ignore haiku.rag.yaml
This commit is contained in:
parent
4164895514
commit
13cc453e9d
2 changed files with 17 additions and 3 deletions
|
|
@ -1,9 +1,18 @@
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
# Prevent tests from loading user's local haiku.rag.yaml by setting env var
|
||||||
import yaml
|
# to an empty config file BEFORE any haiku.rag imports.
|
||||||
from datasets import Dataset, load_dataset, load_from_disk
|
# This ensures tests always use default config values.
|
||||||
|
_test_config_dir = tempfile.mkdtemp()
|
||||||
|
_test_config_path = Path(_test_config_dir) / "test-defaults.yaml"
|
||||||
|
_test_config_path.write_text("{}") # Empty YAML = use all defaults
|
||||||
|
os.environ["HAIKU_RAG_CONFIG_PATH"] = str(_test_config_path)
|
||||||
|
|
||||||
|
import pytest # noqa: E402
|
||||||
|
import yaml # noqa: E402
|
||||||
|
from datasets import Dataset, load_dataset, load_from_disk # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ embeddings:
|
||||||
|
|
||||||
def test_find_config_file_cwd(tmp_path, monkeypatch):
|
def test_find_config_file_cwd(tmp_path, monkeypatch):
|
||||||
"""Test finding config in current directory."""
|
"""Test finding config in current directory."""
|
||||||
|
monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False)
|
||||||
monkeypatch.chdir(tmp_path)
|
monkeypatch.chdir(tmp_path)
|
||||||
config_file = tmp_path / "haiku.rag.yaml"
|
config_file = tmp_path / "haiku.rag.yaml"
|
||||||
config_file.write_text("environment: production")
|
config_file.write_text("environment: production")
|
||||||
|
|
@ -40,6 +41,7 @@ def test_find_config_file_cwd(tmp_path, monkeypatch):
|
||||||
|
|
||||||
def test_find_config_file_user_config(tmp_path, monkeypatch):
|
def test_find_config_file_user_config(tmp_path, monkeypatch):
|
||||||
"""Test finding config in user config directory."""
|
"""Test finding config in user config directory."""
|
||||||
|
monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False)
|
||||||
monkeypatch.chdir(tmp_path)
|
monkeypatch.chdir(tmp_path)
|
||||||
|
|
||||||
# Mock get_default_data_dir to return tmp_path
|
# Mock get_default_data_dir to return tmp_path
|
||||||
|
|
@ -79,6 +81,7 @@ def test_find_config_file_env_var(tmp_path, monkeypatch):
|
||||||
|
|
||||||
def test_find_config_file_not_found(tmp_path, monkeypatch):
|
def test_find_config_file_not_found(tmp_path, monkeypatch):
|
||||||
"""Test returning None when no config found."""
|
"""Test returning None when no config found."""
|
||||||
|
monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False)
|
||||||
monkeypatch.chdir(tmp_path)
|
monkeypatch.chdir(tmp_path)
|
||||||
|
|
||||||
# Mock get_default_data_dir to return tmp_path
|
# Mock get_default_data_dir to return tmp_path
|
||||||
|
|
@ -103,6 +106,8 @@ def test_find_config_file_cli_path_not_exists(tmp_path):
|
||||||
|
|
||||||
def test_config_precedence_cwd_over_user(tmp_path, monkeypatch):
|
def test_config_precedence_cwd_over_user(tmp_path, monkeypatch):
|
||||||
"""Test that cwd config takes precedence over user config."""
|
"""Test that cwd config takes precedence over user config."""
|
||||||
|
monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False)
|
||||||
|
|
||||||
# Create separate directories for cwd and user config
|
# Create separate directories for cwd and user config
|
||||||
cwd_dir = tmp_path / "cwd"
|
cwd_dir = tmp_path / "cwd"
|
||||||
cwd_dir.mkdir()
|
cwd_dir.mkdir()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue