Skip to content

Commit

Permalink
Repair passing of stdio kwargs to PEX.run() (#288)
Browse files Browse the repository at this point in the history
* Add a test to reveal pants integration breakage.
* Repair passing of stdio kwargs to PEX.run().
  • Loading branch information
kwlzn authored Jul 15, 2016
1 parent 8f6243a commit c9252a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 3 additions & 4 deletions pex/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,8 @@ def run(self, args=(), with_chroot=False, blocking=True, setsid=False, **kwargs)
process = Executor.open_process(cmdline,
cwd=self._pex if with_chroot else os.getcwd(),
preexec_fn=os.setsid if setsid else None,
# Explicitly don't redirect stdio for this execution.
stdin=None,
stdout=None,
stderr=None,
stdin=kwargs.pop('stdin', None),
stdout=kwargs.pop('stdout', None),
stderr=kwargs.pop('stderr', None),
**kwargs)
return process.wait() if blocking else process
1 change: 0 additions & 1 deletion tests/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from pex.executor import Executor


TEST_EXECUTABLE = '/a/nonexistent/path/to/nowhere'
TEST_CMD_LIST = [TEST_EXECUTABLE, '--version']
TEST_CMD_STR = ' '.join(TEST_CMD_LIST)
Expand Down
23 changes: 21 additions & 2 deletions tests/test_pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
from types import ModuleType

import pytest
from twitter.common.contextutil import temporary_dir

from pex.compatibility import WINDOWS, nested, to_bytes
from pex.installer import EggInstaller, WheelInstaller
from pex.pex import PEX
from pex.testing import make_installer, run_simple_pex_test
from pex.testing import (
make_installer,
named_temporary_file,
run_simple_pex_test,
temporary_dir,
write_simple_pex
)
from pex.util import DistributionHelper

try:
Expand Down Expand Up @@ -187,3 +192,17 @@ def test_pex_script(installer_impl, project_name, zip_safe):
so, rc = run_simple_pex_test('', env=env_copy, dists=[bdist])
assert rc == 1, so.decode('utf-8')
assert b'Unable to parse' in so


def test_pex_run():
with named_temporary_file() as fake_stdout:
with temporary_dir() as temp_dir:
pex = write_simple_pex(
temp_dir,
'import sys; sys.stdout.write("hello"); sys.stderr.write("hello"); sys.exit(0)'
)
rc = PEX(pex.path()).run(stdin=None, stdout=fake_stdout, stderr=fake_stdout)
assert rc == 0

fake_stdout.seek(0)
assert fake_stdout.read() == b'hellohello'

0 comments on commit c9252a0

Please sign in to comment.