MCPcopy
hub / github.com/pex-tool/pex / test_pex_paths

Function test_pex_paths

tests/test_pex.py:532–564  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

530
531
532def 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

Callers

nothing calls this directly

Calls 8

named_temporary_fileFunction · 0.90
temporary_dirFunction · 0.90
write_simple_pexFunction · 0.90
PEXClass · 0.90
joinMethod · 0.45
runMethod · 0.45
pathMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected