Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions tests/test_zero_dep_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,60 @@

This guards the architectural contract documented in ``tech.md``
ADR-002. Marked ``slow`` because it creates a real venv.

Uses ``uv venv`` + ``uv pip`` rather than stdlib ``venv``/``pip`` because
``ensurepip`` aborts on some Python builds (observed on cpython 3.11.14
macOS-aarch64).
"""

from __future__ import annotations

import shutil
import subprocess
import sys
import venv
from pathlib import Path

import pytest

REPO_ROOT = Path(__file__).resolve().parent.parent

_UV = shutil.which("uv")

@pytest.mark.slow
@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="venv layout differs on Windows; covered on Linux/macOS",
_requires_uv = pytest.mark.skipif(
_UV is None,
reason="uv is required to build the isolated test venv (stdlib ensurepip is unreliable)",
)
def test_attune_help_imports_without_authoring_extra(tmp_path: Path) -> None:
venv_dir = tmp_path / "venv"
venv.create(venv_dir, with_pip=True)
py = venv_dir / "bin" / "python"
pip = venv_dir / "bin" / "pip"


def _make_venv(venv_dir: Path) -> Path:
"""Create a venv at ``venv_dir`` via ``uv venv`` and return its python."""
subprocess.run(
[str(pip), "install", "--quiet", "python-frontmatter"],
[_UV, "venv", "--quiet", str(venv_dir)],
check=True,
capture_output=True,
)
return venv_dir / "bin" / "python"


def _install(py: Path, *args: str) -> None:
subprocess.run(
[str(pip), "install", "--quiet", "--no-deps", "-e", str(REPO_ROOT)],
[_UV, "pip", "install", "--quiet", "--python", str(py), *args],
check=True,
capture_output=True,
)


@pytest.mark.slow
@_requires_uv
@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="venv layout differs on Windows; covered on Linux/macOS",
)
def test_attune_help_imports_without_authoring_extra(tmp_path: Path) -> None:
py = _make_venv(tmp_path / "venv")
_install(py, "python-frontmatter")
_install(py, "--no-deps", "-e", str(REPO_ROOT))

base = subprocess.run(
[str(py), "-c", "import attune_help; print('ok')"],
capture_output=True,
Expand All @@ -55,6 +73,7 @@ def test_attune_help_imports_without_authoring_extra(tmp_path: Path) -> None:


@pytest.mark.slow
@_requires_uv
@pytest.mark.skipif(
sys.platform.startswith("win"),
reason="venv layout differs on Windows; covered on Linux/macOS",
Expand All @@ -69,21 +88,9 @@ def test_attune_help_imports_without_authoring_extra(tmp_path: Path) -> None:
],
)
def test_shim_imports_fail_helpfully_without_authoring(tmp_path: Path, shim_module: str) -> None:
venv_dir = tmp_path / "venv"
venv.create(venv_dir, with_pip=True)
py = venv_dir / "bin" / "python"
pip = venv_dir / "bin" / "pip"

subprocess.run(
[str(pip), "install", "--quiet", "python-frontmatter"],
check=True,
capture_output=True,
)
subprocess.run(
[str(pip), "install", "--quiet", "--no-deps", "-e", str(REPO_ROOT)],
check=True,
capture_output=True,
)
py = _make_venv(tmp_path / "venv")
_install(py, "python-frontmatter")
_install(py, "--no-deps", "-e", str(REPO_ROOT))

result = subprocess.run(
[str(py), "-c", f"import {shim_module}"],
Expand Down
Loading