1
- import os
2
1
import shutil
3
2
import subprocess
4
3
import sys
14
13
from pipx .util import PipxError
15
14
16
15
17
- def py_which (name ):
18
- if name == "py" :
16
+ @pytest .mark .parametrize ("venv" , [True , False ])
17
+ def test_windows_python_with_version (monkeypatch , venv ):
18
+ def which (name ):
19
19
return "py"
20
20
21
-
22
- def test_windows_python_with_version_no_venv (monkeypatch ):
23
- monkeypatch .setattr (pipx .interpreter , "has_venv" , lambda : False )
24
- monkeypatch .setattr (shutil , "which" , py_which )
25
- assert find_py_launcher_python ("3.9" ) == "py"
26
- assert os .environ .get ("PY_PYTHON" ) == "3.9"
27
-
28
-
29
- def test_windows_python_with_version_with_venv (monkeypatch ):
30
- monkeypatch .setattr (pipx .interpreter , "has_venv" , lambda : True )
31
- monkeypatch .setattr (shutil , "which" , py_which )
32
- assert find_py_launcher_python ("3.9" ) == "py"
33
- assert os .environ .get ("PY_PYTHON" ) == "3.9"
21
+ major = sys .version_info .major
22
+ minor = sys .version_info .minor
23
+ monkeypatch .setattr (pipx .interpreter , "has_venv" , lambda : venv )
24
+ monkeypatch .setattr (shutil , "which" , which )
25
+ assert find_py_launcher_python (f"{ major } .{ minor } " ).endswith (
26
+ f"Python{ major } { minor } \\ python.exe"
27
+ )
34
28
35
29
36
30
def test_windows_python_no_version_with_venv (monkeypatch ):
@@ -39,8 +33,11 @@ def test_windows_python_no_version_with_venv(monkeypatch):
39
33
40
34
41
35
def test_windows_python_no_version_no_venv_with_py (monkeypatch ):
36
+ def which (name ):
37
+ return "py"
38
+
42
39
monkeypatch .setattr (pipx .interpreter , "has_venv" , lambda : False )
43
- monkeypatch .setattr (shutil , "which" , py_which )
40
+ monkeypatch .setattr (shutil , "which" , which )
44
41
assert _find_default_windows_python () == "py"
45
42
46
43
0 commit comments