Add QueueRepositoryInterface with memory and file-backed adapters.
PR Title Check / check-title (pull_request) Successful in 9s
Code Quality Pipeline / code-quality (pull_request) Failing after 53s
Test Python Package / unit-tests (pull_request) Successful in 1m1s
Test Python Package / integration-tests (pull_request) Successful in 1m44s
Test Python Package / coverage-report (pull_request) Successful in 13s
PR Title Check / check-title (pull_request) Successful in 9s
Code Quality Pipeline / code-quality (pull_request) Failing after 53s
Test Python Package / unit-tests (pull_request) Successful in 1m1s
Test Python Package / integration-tests (pull_request) Successful in 1m44s
Test Python Package / coverage-report (pull_request) Successful in 13s
Provide a generic disk-backed FIFO queue with configurable path, retention, and dedup keys so consumers can buffer items across restarts without optional extras. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
co-authored by
Cursor
parent
88ea7f06ab
commit
4f58c32dd6
@@ -0,0 +1,56 @@
|
||||
"""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"
|
||||
Reference in New Issue
Block a user