@@ -18,6 +18,29 @@ def _project_root() -> Path:
1818 return root
1919
2020
21+ def _venv_python (venv_dir : Path ) -> str :
22+ """Return the path to the Python executable inside a venv."""
23+ if sys .platform == "win32" :
24+ return str (venv_dir / "Scripts" / "python.exe" )
25+ return str (venv_dir / "bin" / "python" )
26+
27+
28+ def _create_venv_and_install (tmp_path : Path ) -> str :
29+ """Create a venv at *tmp_path*/venv, install pyfuse, return python path."""
30+ venv_dir = tmp_path / "venv"
31+ venv .create (str (venv_dir ), with_pip = True )
32+ python = _venv_python (venv_dir )
33+
34+ result = subprocess .run (
35+ [python , "-m" , "pip" , "install" , str (_project_root ()), "--quiet" ],
36+ capture_output = True ,
37+ text = True ,
38+ timeout = 120 ,
39+ )
40+ assert result .returncode == 0 , f"pip install failed:\n { result .stderr } "
41+ return python
42+
43+
2144class TestVersionConsistency :
2245 """Ensure the package exposes a consistent version."""
2346
@@ -54,35 +77,17 @@ class TestIsolatedInstallation:
5477
5578 def test_install_and_import_no_extras (self , tmp_path : Path ) -> None :
5679 """Package installs and imports without optional dependencies."""
57- venv_dir = tmp_path / "venv"
58- venv .create (str (venv_dir ), with_pip = True )
59-
60- if sys .platform == "win32" :
61- python = str (venv_dir / "Scripts" / "python.exe" )
62- else :
63- python = str (venv_dir / "bin" / "python" )
64-
65- root = _project_root ()
66-
67- # Install the package (no extras)
68- result = subprocess .run (
69- [python , "-m" , "pip" , "install" , str (root ), "--quiet" ],
70- capture_output = True ,
71- text = True ,
72- timeout = 120 ,
80+ python = _create_venv_and_install (tmp_path )
81+
82+ script = (
83+ "import pyfuse\n "
84+ "print(pyfuse.__version__)\n "
85+ "print(pyfuse.serialize)\n "
86+ "print(pyfuse.trace)\n "
87+ "print(pyfuse.get_graph())\n "
7388 )
74- assert result .returncode == 0 , f"pip install failed:\n { result .stderr } "
75-
76- # Verify import works
7789 result = subprocess .run (
78- [
79- python , "-c" ,
80- "import pyfuse; "
81- "print(pyfuse.__version__); "
82- "print(pyfuse.serialize); "
83- "print(pyfuse.trace); "
84- "print(pyfuse.get_graph()); "
85- ],
90+ [python , "-c" , script ],
8691 capture_output = True ,
8792 text = True ,
8893 timeout = 30 ,
@@ -102,30 +107,12 @@ def test_install_version_matches(self, tmp_path: Path) -> None:
102107 except ModuleNotFoundError :
103108 import tomli as tomllib # type: ignore[no-redef]
104109
105- venv_dir = tmp_path / "venv"
106- venv .create (str (venv_dir ), with_pip = True )
107-
108- if sys .platform == "win32" :
109- python = str (venv_dir / "Scripts" / "python.exe" )
110- else :
111- python = str (venv_dir / "bin" / "python" )
112-
113- root = _project_root ()
110+ python = _create_venv_and_install (tmp_path )
114111
115- pyproject = root / "pyproject.toml"
112+ pyproject = _project_root () / "pyproject.toml"
116113 with open (pyproject , "rb" ) as f :
117114 expected_version = tomllib .load (f )["project" ]["version" ]
118115
119- # Install
120- result = subprocess .run (
121- [python , "-m" , "pip" , "install" , str (root ), "--quiet" ],
122- capture_output = True ,
123- text = True ,
124- timeout = 120 ,
125- )
126- assert result .returncode == 0 , f"pip install failed:\n { result .stderr } "
127-
128- # Check version
129116 result = subprocess .run (
130117 [python , "-c" , "import pyfuse; print(pyfuse.__version__)" ],
131118 capture_output = True ,
@@ -137,23 +124,7 @@ def test_install_version_matches(self, tmp_path: Path) -> None:
137124
138125 def test_cli_entrypoint (self , tmp_path : Path ) -> None :
139126 """The ``pyfuse`` CLI entry point is installed and functional."""
140- venv_dir = tmp_path / "venv"
141- venv .create (str (venv_dir ), with_pip = True )
142-
143- if sys .platform == "win32" :
144- python = str (venv_dir / "Scripts" / "python.exe" )
145- else :
146- python = str (venv_dir / "bin" / "python" )
147-
148- root = _project_root ()
149-
150- result = subprocess .run (
151- [python , "-m" , "pip" , "install" , str (root ), "--quiet" ],
152- capture_output = True ,
153- text = True ,
154- timeout = 120 ,
155- )
156- assert result .returncode == 0 , f"pip install failed:\n { result .stderr } "
127+ python = _create_venv_and_install (tmp_path )
157128
158129 # Run ``pyfuse info`` via the entry point
159130 result = subprocess .run (
0 commit comments