acupedia-ops/tests/common/test_workspace_paths.py

50 lines
1.2 KiB
Python

from pathlib import Path
import pytest
from acupedia_ops.common.workspace_paths import (
resolve_command,
resolve_workspace_path,
workspace_base_path,
)
def test_workspace_base_must_be_absolute(monkeypatch) -> None:
monkeypatch.setenv("ACUPEDIA_WORKSPACE_BASE_PATH", "relative/workspace")
with pytest.raises(ValueError):
workspace_base_path()
def test_relative_path_uses_workspace_base(tmp_path: Path) -> None:
base = (tmp_path / "workspace").resolve()
base.mkdir()
assert resolve_workspace_path(
"acupedia-api",
base_path=base,
) == (base / "acupedia-api").resolve()
def test_absolute_path_is_preserved(tmp_path: Path) -> None:
absolute = (tmp_path / "api").resolve()
assert resolve_workspace_path(
absolute,
base_path=tmp_path / "other",
) == absolute
def test_command_executable_path_uses_workspace_base(tmp_path: Path) -> None:
base = (tmp_path / "workspace").resolve()
base.mkdir()
command = resolve_command(
"acupedia-api/.venv/bin/acupedia-bootstrap --flag value",
base_path=base,
)
assert command[0] == str(
(base / "acupedia-api/.venv/bin/acupedia-bootstrap").resolve()
)
assert command[1:] == ["--flag", "value"]