Skip to content

Commit 7033e22

Browse files
committed
Add test cases for invoking Python via getpath
1 parent 52917c5 commit 7033e22

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/verify_distribution.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
import importlib.machinery
66
import os
7+
from pathlib import Path
78
import struct
9+
import subprocess
810
import sys
11+
import tempfile
912
import unittest
13+
import venv
1014

1115
TERMINFO_DIRS = [
1216
"/etc/terminfo",
@@ -269,6 +273,37 @@ def assertLibc(value):
269273

270274
assertLibc(importlib.machinery.EXTENSION_SUFFIXES[0])
271275

276+
@unittest.skipIf(
277+
sys.version_info[:2] < (3, 14),
278+
"not yet implemented",
279+
)
280+
@unittest.skipIf(os.name == "nt", "no symlinks or argv[0] on Windows")
281+
def test_getpath(self):
282+
def assertPythonWorks(path: Path, argv0: str = None):
283+
output = subprocess.check_output(
284+
[argv0 or path, "-c", "print(42)"], executable=path, text=True
285+
)
286+
self.assertEqual(output.strip(), "42")
287+
288+
with tempfile.TemporaryDirectory(prefix="verify-distribution-") as t:
289+
tmpdir = Path(t)
290+
symlink = tmpdir / "python"
291+
symlink.symlink_to(sys.executable)
292+
with self.subTest(msg="symlink without venv"):
293+
assertPythonWorks(symlink)
294+
295+
# TODO: --copies does not work right
296+
for flag in ("--symlinks",):
297+
with self.subTest(flag=flag):
298+
venv = tmpdir / f"venv_{flag}"
299+
subprocess.check_call(
300+
[symlink, "-m", "venv", flag, "--without-pip", venv]
301+
)
302+
assertPythonWorks(venv / "bin" / "python")
303+
304+
with self.subTest(msg="weird argv[0]"):
305+
assertPythonWorks(sys.executable, argv0="/dev/null")
306+
272307

273308
if __name__ == "__main__":
274309
unittest.main()

0 commit comments

Comments
 (0)