Coverage for tests / test_wheel_install.py: 100%
22 statements
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 16:38 +0000
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-13 16:38 +0000
1import subprocess
2import sys
3import venv as venv_module
4from pathlib import Path
6import pytest
8_PACKAGE_DIR = Path(__file__).parent.parent
11def test_pth_in_site_packages_after_wheel_install(tmp_path):
12 """Non-editable wheel install must put vivarium_compat.pth in site-packages."""
13 venv_dir = tmp_path / "venv"
14 venv_module.create(str(venv_dir), with_pip=True, clear=True)
16 pip = venv_dir / "bin" / "pip"
17 python = venv_dir / "bin" / "python"
19 subprocess.run(
20 [str(pip), "install", str(_PACKAGE_DIR), "--no-cache-dir", "-q"],
21 check=True,
22 )
24 # .pth must be in site-packages, not sys.prefix
25 result = subprocess.run(
26 [
27 str(python),
28 "-c",
29 "import site, pathlib; "
30 "sp = pathlib.Path(site.getsitepackages()[0]); "
31 "print((sp / 'vivarium_compat.pth').exists())",
32 ],
33 capture_output=True,
34 text=True,
35 check=True,
36 )
37 assert result.stdout.strip() == "True", (
38 "vivarium_compat.pth not found in site-packages — "
39 "check [tool.hatch.build.targets.wheel.force-include] in pyproject.toml"
40 )
43def test_hook_active_at_startup_after_wheel_install(tmp_path):
44 """After wheel install, _CompatFinder must be in sys.meta_path before any user code."""
45 venv_dir = tmp_path / "venv"
46 venv_module.create(str(venv_dir), with_pip=True, clear=True)
48 pip = venv_dir / "bin" / "pip"
49 python = venv_dir / "bin" / "python"
51 subprocess.run(
52 [str(pip), "install", str(_PACKAGE_DIR), "--no-cache-dir", "-q"],
53 check=True,
54 )
56 result = subprocess.run(
57 [
58 str(python),
59 "-c",
60 "import sys; "
61 "from vivarium._compat._compat import _CompatFinder; "
62 "print(any(isinstance(f, _CompatFinder) for f in sys.meta_path))",
63 ],
64 capture_output=True,
65 text=True,
66 check=True,
67 )
68 assert (
69 result.stdout.strip() == "True"
70 ), "_CompatFinder not in sys.meta_path at startup — .pth file may not be firing"