Introduce typed config objects, optional adapter injection, and .env loading to simplify testing while preserving env-based defaults for production usage. Co-authored-by: Cursor <[email protected]>
27 lines
713 B
Python
27 lines
713 B
Python
"""Unit tests for dotenv_loader."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from python_repositories.config.dotenv_loader import load_dotenv
|
|
|
|
|
|
def test_load_dotenv_loads_file(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
env_file = tmp_path / ".env"
|
|
env_file.write_text("DOTENV_TEST_VAR=loaded_value\n")
|
|
monkeypatch.delenv("DOTENV_TEST_VAR", raising=False)
|
|
loaded = load_dotenv(env_file)
|
|
assert loaded is True
|
|
assert os.getenv("DOTENV_TEST_VAR") == "loaded_value"
|
|
|
|
|
|
def test_load_dotenv_returns_false_for_missing_file(tmp_path: Path) -> None:
|
|
missing = tmp_path / "missing.env"
|
|
assert load_dotenv(missing) is False
|