-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathconftest.py
More file actions
83 lines (69 loc) · 3.1 KB
/
Copy pathconftest.py
File metadata and controls
83 lines (69 loc) · 3.1 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: utf-8 -*-
"""Shared fixtures.
Most tests build *synthetic* distribution layouts in tmp_path: wppm's target
resolution is pure path logic, so a directory tree with an empty `python.exe`
in it exercises the real code without needing a real interpreter. That keeps
the suite fast, offline and deterministic.
Only the end-to-end CLI tests need a real interpreter, and they use a plain
`python -m venv` (which bundles pip via ensurepip, so still no network).
"""
import subprocess
import sys
from pathlib import Path
import pytest
IS_WINDOWS = sys.platform == "win32"
windows_only = pytest.mark.skipif(
not IS_WINDOWS, reason="wppm targets the Windows layout (python.exe / Scripts)"
)
def write_dist(site_packages: Path, name: str, version: str, requires=(),
summary: str = "", extras=()) -> Path:
"""Write a minimal .dist-info so importlib.metadata can discover the package."""
dist_info = site_packages / f"{name.replace('-', '_')}-{version}.dist-info"
dist_info.mkdir(parents=True, exist_ok=True)
lines = ["Metadata-Version: 2.1", f"Name: {name}", f"Version: {version}"]
if summary:
lines.append(f"Summary: {summary}")
lines += [f"Provides-Extra: {e}" for e in extras]
lines += [f"Requires-Dist: {r}" for r in requires]
(dist_info / "METADATA").write_text("\n".join(lines) + "\n", encoding="utf-8")
(dist_info / "INSTALLER").write_text("pytest\n", encoding="utf-8")
return dist_info
@pytest.fixture
def winpython_layout(tmp_path: Path) -> Path:
"""WinPython/plain install: python.exe at the root, Lib/site-packages beside it.
Also creates the distribution-root `scripts/` sibling that holds env.bat --
that directory is NOT a venv Scripts dir and must not be mistaken for one.
"""
root = tmp_path / "WPy64-31470b3" / "python"
(root / "Lib" / "site-packages").mkdir(parents=True)
(root / "Scripts").mkdir()
(root / "python.exe").write_bytes(b"MZ")
distro_root = root.parent
(distro_root / "scripts").mkdir()
(distro_root / "scripts" / "env.bat").write_text("@echo off\n", encoding="utf-8")
(distro_root / "wheelhouse").mkdir()
return root
@pytest.fixture
def venv_layout(tmp_path: Path) -> Path:
"""venv: python.exe under Scripts/, Lib/site-packages at the root, pyvenv.cfg marker."""
root = tmp_path / "myvenv"
(root / "Scripts").mkdir(parents=True)
(root / "Lib" / "site-packages").mkdir(parents=True)
(root / "Scripts" / "python.exe").write_bytes(b"MZ")
(root / "pyvenv.cfg").write_text(
"home = C:\\Python\nversion = 3.14.6\n", encoding="utf-8"
)
return root
@pytest.fixture(scope="session")
def real_venv(tmp_path_factory) -> Path:
"""A genuine venv. ensurepip is bundled, so this needs no network."""
if not IS_WINDOWS:
pytest.skip("wppm targets the Windows layout")
target = tmp_path_factory.mktemp("real") / "venv"
proc = subprocess.run(
[sys.executable, "-m", "venv", str(target)],
capture_output=True, text=True,
)
if proc.returncode != 0:
pytest.skip(f"could not create a venv: {proc.stderr.strip()[:200]}")
return target