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

Function test_compile

tests/tools/commands/test_venv.py:550–632  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

548
549
550def test_compile(tmpdir):
551 # type: (Any) -> None
552
553 def collect_files(
554 root_dir, # type: str
555 extension, # type: str
556 ):
557 # type: (...) -> Set[str]
558 return {
559 os.path.relpath(os.path.join(root, f), root_dir)
560 for root, _, files in os.walk(root_dir, followlinks=False)
561 for f in files
562 if f.endswith(extension)
563 }
564
565 pex_file = os.path.join(str(tmpdir), "compile.pex")
566 src = os.path.join(str(tmpdir), "src")
567 with safe_open(os.path.join(src, "main.py"), "w") as fp:
568 fp.write(
569 dedent(
570 """\
571 from colors import yellow
572
573
574 print(yellow("Slartibartfast"))
575 """
576 )
577 )
578 result = run_pex_command(
579 args=["-D", src, "ansicolors==1.0.2", "-m", "main", "--include-tools", "-o", pex_file]
580 )
581 result.assert_success()
582
583 venv = os.path.join(str(tmpdir), "venv")
584 subprocess.check_call(args=[pex_file, "venv", venv], env=make_env(PEX_TOOLS=1))
585 # N.B.: The right way to discover the site-packages dir is via site.getsitepackages().
586 # Unfortunately we use an old version of virtualenv to create PyPy <= 3.7 and CPython 2.7 venvs
587 # and it does not add a getsitepackages function to site.py; so we cheat.
588 if IS_PYPY and PY_VER <= (3, 7):
589 site_packages = "site-packages"
590 else:
591 site_packages = os.path.join(
592 "lib",
593 "{python}{major}.{minor}".format(
594 python="pypy" if IS_PYPY else "python",
595 major=sys.version_info[0],
596 minor=sys.version_info[1],
597 ),
598 "site-packages",
599 )
600
601 # Ensure we have at least the basic direct dependency python files we expect.
602 venv_py_files = collect_files(venv, ".py")
603 assert os.path.join(site_packages, "main.py") in venv_py_files
604 assert os.path.join(site_packages, "colors.py") in venv_py_files
605 assert "__main__.py" in venv_py_files
606
607 compile_venv = os.path.join(str(tmpdir), "compile.venv")

Callers

nothing calls this directly

Calls 7

safe_openFunction · 0.90
run_pex_commandFunction · 0.90
collect_filesFunction · 0.85
assert_successMethod · 0.80
make_envFunction · 0.70
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected