|
4 | 4 |
|
5 | 5 | import importlib.machinery |
6 | 6 | import os |
| 7 | +from pathlib import Path |
7 | 8 | import struct |
| 9 | +import subprocess |
8 | 10 | import sys |
| 11 | +import tempfile |
9 | 12 | import unittest |
| 13 | +import venv |
10 | 14 |
|
11 | 15 | TERMINFO_DIRS = [ |
12 | 16 | "/etc/terminfo", |
@@ -269,6 +273,37 @@ def assertLibc(value): |
269 | 273 |
|
270 | 274 | assertLibc(importlib.machinery.EXTENSION_SUFFIXES[0]) |
271 | 275 |
|
| 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 | + |
272 | 307 |
|
273 | 308 | if __name__ == "__main__": |
274 | 309 | unittest.main() |
0 commit comments