Skip to content

Commit 7e51c1e

Browse files
committed
Add test cases for invoking Python via getpath
1 parent a28a263 commit 7e51c1e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/verify_distribution.py

Lines changed: 34 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,36 @@ 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+
def test_getpath(self):
281+
def assertPythonWorks(path: Path, argv0: str = None):
282+
output = subprocess.check_output(
283+
[argv0 or path, "-c", "print(42)"], executable=path, text=True
284+
)
285+
self.assertEqual(output.strip(), "42")
286+
287+
with tempfile.TemporaryDirectory(prefix="verify-distribution-") as t:
288+
tmpdir = Path(t)
289+
symlink = tmpdir / "python"
290+
symlink.symlink_to(sys.executable)
291+
with self.subTest(msg="symlink without venv"):
292+
assertPythonWorks(symlink)
293+
294+
# TODO: --copies does not work right
295+
for flag in ("--symlinks",):
296+
with self.subTest(flag=flag):
297+
venv = tmpdir / f"venv_{flag}"
298+
subprocess.check_call(
299+
[symlink, "-m", "venv", flag, "--without-pip", venv]
300+
)
301+
assertPythonWorks(venv / "bin" / "python")
302+
303+
with self.subTest(msg="weird argv[0]"):
304+
assertPythonWorks(sys.executable, argv0="/dev/null")
305+
272306

273307
if __name__ == "__main__":
274308
unittest.main()

0 commit comments

Comments
 (0)