Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

4.3 KB
Raw Blame
"""Extended tests for paths module - covering untested directory functions."""

from pathlib import Path

from local_deep_research.config.paths import (
    get_library_directory,
    get_config_directory,
    get_models_directory,
    get_research_outputs_directory,
)


class TestGetLibraryDirectory:
    """Tests for get_library_directory function."""

    def test_returns_library_subdirectory(self, mock_env_data_dir):
        """Should return library subdirectory of data dir."""
        result = get_library_directory()
        assert result.name == "library"
        assert result.parent == mock_env_data_dir

    def test_creates_directory(self, mock_env_data_dir):
        """Should create directory if it doesn't exist."""
        result = get_library_directory()
        assert result.exists()
        assert result.is_dir()

    def test_returns_path_object(self, mock_env_data_dir):
        """Should return Path object."""
        result = get_library_directory()
        assert isinstance(result, Path)

    def test_idempotent_when_directory_exists(self, mock_env_data_dir):
        """Calling twice should work fine when directory already exists."""
        result1 = get_library_directory()
        result2 = get_library_directory()
        assert result1 == result2
        assert result1.exists()


class TestGetConfigDirectory:
    """Tests for get_config_directory function."""

    def test_returns_config_subdirectory(self, mock_env_data_dir):
        """Should return config subdirectory of data dir."""
        result = get_config_directory()
        assert result.name == "config"
        assert result.parent == mock_env_data_dir

    def test_creates_directory(self, mock_env_data_dir):
        """Should create directory if it doesn't exist."""
        result = get_config_directory()
        assert result.exists()
        assert result.is_dir()

    def test_returns_path_object(self, mock_env_data_dir):
        """Should return Path object."""
        result = get_config_directory()
        assert isinstance(result, Path)


class TestGetModelsDirectory:
    """Tests for get_models_directory function."""

    def test_returns_models_subdirectory(self, mock_env_data_dir):
        """Should return models subdirectory of data dir."""
        result = get_models_directory()
        assert result.name == "models"
        assert result.parent == mock_env_data_dir

    def test_creates_directory(self, mock_env_data_dir):
        """Should create directory if it doesn't exist."""
        result = get_models_directory()
        assert result.exists()
        assert result.is_dir()

    def test_returns_path_object(self, mock_env_data_dir):
        """Should return Path object."""
        result = get_models_directory()
        assert isinstance(result, Path)


class TestAllDirectoriesUseDataDir:
    """Verify all directory functions consistently use get_data_directory as base."""

    def test_all_subdirectories_share_same_parent(self, mock_env_data_dir):
        """All subdirectory functions should use the same data directory."""
        library = get_library_directory()
        config = get_config_directory()
        models = get_models_directory()
        outputs = get_research_outputs_directory()

        assert library.parent == mock_env_data_dir
        assert config.parent == mock_env_data_dir
        assert models.parent == mock_env_data_dir
        assert outputs.parent == mock_env_data_dir

    def test_env_var_override_affects_all_directories(
        self, tmp_path, monkeypatch
    ):
        """LDR_DATA_DIR override should affect all directory functions."""
        custom_dir = tmp_path / "custom_data"
        custom_dir.mkdir()
        monkeypatch.setenv("LDR_DATA_DIR", str(custom_dir))

        library = get_library_directory()
        config = get_config_directory()
        models = get_models_directory()

        assert library.parent == custom_dir
        assert config.parent == custom_dir
        assert models.parent == custom_dir

    def test_all_directories_are_distinct(self, mock_env_data_dir):
        """All directory functions should return different paths."""
        library = get_library_directory()
        config = get_config_directory()
        models = get_models_directory()
        outputs = get_research_outputs_directory()

        paths = {library, config, models, outputs}
        assert len(paths) == 4, "All directory paths should be unique"