()
| 530 | |
| 531 | |
| 532 | def test_pex_paths(): |
| 533 | # type: () -> None |
| 534 | # Tests that PEX_PATH allows importing sources from the referenced pex. |
| 535 | with named_temporary_file() as fake_stdout: |
| 536 | with temporary_dir() as temp_dir: |
| 537 | pex1_path = os.path.join(temp_dir, "pex1") |
| 538 | write_simple_pex( |
| 539 | pex1_path, |
| 540 | sources=[ |
| 541 | ("foo_pkg/__init__.py", ""), |
| 542 | ("foo_pkg/foo_module.py", 'def foo_func():\n return "42"'), |
| 543 | ], |
| 544 | ) |
| 545 | |
| 546 | pex2_path = os.path.join(temp_dir, "pex2") |
| 547 | pex2 = write_simple_pex( |
| 548 | pex2_path, |
| 549 | "import sys; from bar_pkg.bar_module import bar_func; " |
| 550 | "sys.stdout.write(bar_func()); sys.exit(0)", |
| 551 | sources=[ |
| 552 | ("bar_pkg/__init__.py", ""), |
| 553 | ( |
| 554 | "bar_pkg/bar_module.py", |
| 555 | "from foo_pkg.foo_module import foo_func\ndef bar_func():\n return foo_func()", |
| 556 | ), |
| 557 | ], |
| 558 | ) |
| 559 | |
| 560 | rc = PEX(pex2.path()).run(stdin=None, stdout=fake_stdout, env={"PEX_PATH": pex1_path}) |
| 561 | assert rc == 0 |
| 562 | |
| 563 | fake_stdout.seek(0) |
| 564 | assert fake_stdout.read() == b"42" |
| 565 | |
| 566 | |
| 567 | @contextmanager |
nothing calls this directly
no test coverage detected