Skip to content

Commit e1daa30

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

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,8 +4,11 @@
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
1013

1114
TERMINFO_DIRS = [
@@ -269,6 +272,37 @@ def assertLibc(value):
269272

270273
assertLibc(importlib.machinery.EXTENSION_SUFFIXES[0])
271274

275+
@unittest.skipIf(
276+
sys.version_info[:2] < (3, 14),
277+
"not yet implemented",
278+
)
279+
@unittest.skipIf(os.name == "nt", "no symlinks or argv[0] on Windows")
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)