()
| 474 | |
| 475 | |
| 476 | def test_pex_executable(): |
| 477 | # type: () -> None |
| 478 | # Tests that pex keeps executable permissions |
| 479 | with temporary_dir() as temp_dir: |
| 480 | pex_dir = os.path.join(temp_dir, "pex_dir") |
| 481 | safe_mkdir(pex_dir) |
| 482 | |
| 483 | with open(os.path.join(pex_dir, "exe.py"), "w") as fp: |
| 484 | fp.write( |
| 485 | textwrap.dedent( |
| 486 | """ |
| 487 | import subprocess |
| 488 | import os |
| 489 | import sys |
| 490 | import my_package |
| 491 | path = os.path.join(os.path.dirname(my_package.__file__), 'bin/start.sh') |
| 492 | sys.stdout.write(subprocess.check_output([path]).decode('utf-8')) |
| 493 | """ |
| 494 | ) |
| 495 | ) |
| 496 | |
| 497 | project_content = { |
| 498 | "setup.py": textwrap.dedent( |
| 499 | """ |
| 500 | from setuptools import setup |
| 501 | |
| 502 | setup( |
| 503 | name='my_project', |
| 504 | version='0.0.0.0', |
| 505 | zip_safe=True, |
| 506 | packages=['my_package'], |
| 507 | package_data={'my_package': ['bin/*']}, |
| 508 | install_requires=[], |
| 509 | ) |
| 510 | """ |
| 511 | ), |
| 512 | "my_package/__init__.py": 0, |
| 513 | "my_package/bin/start.sh": ( |
| 514 | "#!/usr/bin/env bash\n" "echo 'hello world from start.sh!'" |
| 515 | ), |
| 516 | "my_package/my_module.py": 'def do_something():\n print("hello world!")\n', |
| 517 | } # type: Dict[str, Union[str, int]] |
| 518 | pex_builder = PEXBuilder(path=pex_dir) |
| 519 | with temporary_content(project_content, perms=0o755) as project_dir: |
| 520 | bdist = install_wheel(WheelBuilder(project_dir).bdist()) |
| 521 | pex_builder.add_dist_location(bdist.location) |
| 522 | pex_builder.set_executable(os.path.join(pex_dir, "exe.py")) |
| 523 | pex_builder.freeze() |
| 524 | |
| 525 | app_pex = os.path.join(os.path.join(temp_dir, "out_pex_dir"), "app.pex") |
| 526 | pex_builder.build(app_pex) |
| 527 | std_out, rc = run_simple_pex(app_pex, env={"PEX_ROOT": os.path.join(temp_dir, ".pex")}) |
| 528 | assert rc == 0 |
| 529 | assert std_out.decode("utf-8") == "hello world from start.sh!\n" |
| 530 | |
| 531 | |
| 532 | def test_pex_paths(): |
nothing calls this directly
no test coverage detected