(distribution_helper_import)
| 114 | |
| 115 | |
| 116 | def assert_access_zipped_assets(distribution_helper_import): |
| 117 | # type: (str) -> bytes |
| 118 | test_executable = dedent( |
| 119 | """ |
| 120 | import os |
| 121 | {distribution_helper_import} |
| 122 | temp_dir = DistributionHelper.access_zipped_assets('my_package', 'submodule') |
| 123 | with open(os.path.join(temp_dir, 'mod.py'), 'r') as fp: |
| 124 | for line in fp: |
| 125 | print(line) |
| 126 | """.format( |
| 127 | distribution_helper_import=distribution_helper_import |
| 128 | ) |
| 129 | ) |
| 130 | with temporary_dir() as td1, temporary_dir() as td2: |
| 131 | pb = PEXBuilder(path=td1) |
| 132 | with open(os.path.join(td1, "exe.py"), "w") as fp: |
| 133 | fp.write(test_executable) |
| 134 | pb.set_executable(fp.name) |
| 135 | |
| 136 | submodule = os.path.join(td1, "my_package", "submodule") |
| 137 | safe_mkdir(submodule) |
| 138 | mod_path = os.path.join(submodule, "mod.py") |
| 139 | with open(mod_path, "w") as fp: |
| 140 | fp.write("accessed") |
| 141 | pb.add_source(fp.name, "my_package/submodule/mod.py") |
| 142 | pb.add_source(None, "my_package/__init__.py") |
| 143 | pb.add_source(None, "my_package/submodule/__init__.py") |
| 144 | pex = os.path.join(td2, "app.pex") |
| 145 | pb.build(pex) |
| 146 | |
| 147 | process = PEX(pex, interpreter=pb.interpreter).run( |
| 148 | blocking=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE |
| 149 | ) |
| 150 | stdout, stderr = process.communicate() |
| 151 | assert process.returncode == 0 |
| 152 | assert b"accessed\n" == stdout |
| 153 | return cast(bytes, stderr) |
| 154 | |
| 155 | |
| 156 | def test_access_zipped_assets_integration(): |
no test coverage detected