"""Unit tests for FileQueueConfig.""" from __future__ import annotations from pathlib import Path import pytest from python_repositories.config import FileQueueConfig def test_defaults() -> None: config = FileQueueConfig(path=Path("/tmp/queue.jsonl")) assert config.path == Path("/tmp/queue.jsonl") assert config.max_age_hours == 24 assert config.dedup_keys == () assert config.age_key is None def test_from_env_loads_path(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("FILE_QUEUE_PATH", "/data/items.jsonl") monkeypatch.delenv("FILE_QUEUE_MAX_AGE_HOURS", raising=False) config = FileQueueConfig.from_env(use_dotenv=False) assert config.path == Path("/data/items.jsonl") assert config.max_age_hours == 24 def test_from_env_loads_max_age_hours(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("FILE_QUEUE_PATH", "/data/items.jsonl") monkeypatch.setenv("FILE_QUEUE_MAX_AGE_HOURS", "48") config = FileQueueConfig.from_env(use_dotenv=False) assert config.max_age_hours == 48 def test_from_env_raises_when_path_missing(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.delenv("FILE_QUEUE_PATH", raising=False) with pytest.raises(Exception): FileQueueConfig.from_env(use_dotenv=False) def test_from_env_respects_custom_env_var_names( monkeypatch: pytest.MonkeyPatch, ) -> None: monkeypatch.setenv("CUSTOM_QUEUE_PATH", "/custom/q.jsonl") monkeypatch.setenv("CUSTOM_MAX_AGE", "12") config = FileQueueConfig.from_env( "CUSTOM_QUEUE_PATH", max_age_hours_env_var_name="CUSTOM_MAX_AGE", dedup_keys=("id",), age_key="created_at", use_dotenv=False, ) assert config.path == Path("/custom/q.jsonl") assert config.max_age_hours == 12 assert config.dedup_keys == ("id",) assert config.age_key == "created_at"