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

Method assert_isolation

tests/test_pex.py:360–392  ·  view source on GitHub ↗
(self, inherit_path, expected_output)

Source from the content-addressed store, hash-verified

358 exe = attr.ib() # type: str
359
360 def assert_isolation(self, inherit_path, expected_output):
361 # type: (Union[str, bool], str) -> None
362 env = dict(PYTHONPATH=self.pythonpath)
363 with temporary_dir() as temp_dir:
364 pex_builder = write_simple_pex(
365 temp_dir,
366 pex_info=self.pex_info(inherit_path),
367 dists=self.dists,
368 exe_contents=self.exe,
369 )
370
371 interpreter = PythonInterpreter.get()
372 if PY2:
373 # Under Python 2 venvs (created by Pex via Virtualenv 16.7.12), the venv interpreter
374 # can fail to resolve stdlib weakref internals. We side-step by just resolving out
375 # of the venv since this test is aimed squarely at PYTHONPATH isolation.
376 interpreter = interpreter.resolve_base_interpreter()
377
378 # Test the PEX.run API.
379 process = PEX(pex_builder.path(), interpreter=interpreter).run(
380 stdout=subprocess.PIPE,
381 stderr=subprocess.PIPE,
382 env=env,
383 blocking=False,
384 )
385 stdout, stderr = process.communicate()
386 assert process.returncode == 0, stderr.decode("utf-8")
387 assert expected_output == stdout.decode("utf-8")
388
389 # Test direct PEX execution.
390 assert expected_output == subprocess.check_output(
391 [interpreter.binary, pex_builder.path()], env=env
392 ).decode("utf-8")
393
394
395@pytest.fixture(scope="module")

Calls 10

pex_infoMethod · 0.95
temporary_dirFunction · 0.90
write_simple_pexFunction · 0.90
PEXClass · 0.90
communicateMethod · 0.80
decodeMethod · 0.80
getMethod · 0.45
runMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected