File size: 1,714 Bytes
3a9d4f8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import pytest
from core.paths import env_float, env_int, resolve_path
def test_absolute_path_is_returned_unchanged(tmp_path):
target = tmp_path / "artifact.bin"
assert resolve_path(str(target), "ignored") == target
def test_relative_path_prefers_existing_cwd(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
(tmp_path / "data").mkdir()
assert resolve_path("data", "fallback") == (tmp_path / "data").resolve()
def test_missing_relative_path_falls_back_to_backend_dir():
# "does-not-exist" resolves to BASE_DIR / value when nothing matches.
resolved = resolve_path("definitely-does-not-exist-xyz", "fallback")
assert resolved.name == "definitely-does-not-exist-xyz"
def test_env_int_rejects_invalid_and_non_positive(monkeypatch):
monkeypatch.setenv("TEST_INT", "not-a-number")
assert env_int("TEST_INT", 7) == 7
monkeypatch.setenv("TEST_INT", "0")
assert env_int("TEST_INT", 7) == 7
monkeypatch.setenv("TEST_INT", "12")
assert env_int("TEST_INT", 7) == 12
def test_env_float_rejects_invalid(monkeypatch):
monkeypatch.setenv("TEST_FLOAT", "nan?")
assert env_float("TEST_FLOAT", 1.5) == 1.5
monkeypatch.setenv("TEST_FLOAT", "0.25")
assert env_float("TEST_FLOAT", 1.5) == 0.25
def test_env_float_rejects_nan_and_infinity(monkeypatch):
monkeypatch.setenv("TEST_FLOAT", "nan")
assert env_float("TEST_FLOAT", 1.5) == 1.5
monkeypatch.setenv("TEST_FLOAT", "inf")
assert env_float("TEST_FLOAT", 1.5) == 1.5
monkeypatch.setenv("TEST_FLOAT", "-inf")
assert env_float("TEST_FLOAT", 1.5) == 1.5
def test_resolve_path_none_uses_default():
assert resolve_path(None, "./index_artifacts/x.faiss").name == "x.faiss"
|