Download backend/tests/test_paths.py from StillWorking/sentinel-face-recognition: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/StillWorking/sentinel-face-recognition/resolve/main/backend/tests/test_paths.py
- Command line
-
hf download hf://StillWorking/sentinel-face-recognition/backend/tests/test_paths.py
-
curl -L -o test_paths.py https://huggingface.co/StillWorking/sentinel-face-recognition/resolve/main/backend/tests/test_paths.py
1.71 kB
| 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" | |