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

Function assert_access_zipped_assets

tests/test_util.py:116–153  ·  view source on GitHub ↗
(distribution_helper_import)

Source from the content-addressed store, hash-verified

114
115
116def 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
156def test_access_zipped_assets_integration():

Callers 1

Calls 12

set_executableMethod · 0.95
add_sourceMethod · 0.95
buildMethod · 0.95
temporary_dirFunction · 0.90
PEXBuilderClass · 0.90
safe_mkdirFunction · 0.90
PEXClass · 0.90
castFunction · 0.90
communicateMethod · 0.80
joinMethod · 0.45
writeMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected