| 503 | |
| 504 | |
| 505 | def test_sys_path_leak_for_current(tmpdir): |
| 506 | # type: (Any) -> None |
| 507 | |
| 508 | expected_sys_path = [ |
| 509 | entry |
| 510 | for entry in json.loads( |
| 511 | subprocess.check_output( |
| 512 | args=[ |
| 513 | sys.executable, |
| 514 | "-sE", |
| 515 | "-c", |
| 516 | "import json, sys; json.dump(sys.path, sys.stdout)", |
| 517 | ] |
| 518 | ).decode("utf-8") |
| 519 | ) |
| 520 | # N.B.: We expect the PythonInterpreter infrastructure to elide the implicit "" / CWD |
| 521 | # sys.path entry. |
| 522 | if entry |
| 523 | ] |
| 524 | pex_root = os.path.join(str(tmpdir), "pex_root") |
| 525 | |
| 526 | new_sys_path_entry = os.path.join(str(tmpdir), "not-interpreter-sys-path") |
| 527 | with ENV.patch(PEX_ROOT=pex_root), PythonInterpreter._cleared_memory_cache(): |
| 528 | sys.path.append(new_sys_path_entry) |
| 529 | try: |
| 530 | assert tuple(expected_sys_path) == PythonInterpreter.get().sys_path |
| 531 | finally: |
| 532 | sys.path.pop() |
| 533 | |
| 534 | |
| 535 | def test_create_shebang(tmpdir): |