diff --git a/.travis.yml b/.travis.yml index 286c55598..03f79179c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,12 +8,6 @@ dist: precise # TRAVIS_PYTHON_VERSION -env: - global: - # This is necessary to have consistent testing of methods that rely on falling back to PATH for - # selecting a python interpreter. - - PATH=$PWD/.tox/py36/bin:$PWD/.tox/py27/bin:$PATH - cache: directories: - .pyenv_test diff --git a/tests/test_integration.py b/tests/test_integration.py index 79ee5f975..abf9ef839 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -343,17 +343,18 @@ def test_interpreter_constraints_to_pex_info_py2(): assert set(['>=2.7', '<3']) == set(pex_info.interpreter_constraints) -@pytest.mark.skip('https://github.com/pantsbuild/pex/issues/470') def test_interpreter_constraints_to_pex_info_py3(): - with temporary_dir() as output_dir: - # target python 3 - pex_out_path = os.path.join(output_dir, 'pex_py3.pex') - res = run_pex_command(['--disable-cache', - '--interpreter-constraint=>3', - '-o', pex_out_path]) - res.assert_success() - pex_info = get_pex_info(pex_out_path) - assert ['>3'] == pex_info.interpreter_constraints + py3_interpreter = ensure_python_interpreter('3.6.3') + with environment_as(PATH=os.path.dirname(py3_interpreter)): + with temporary_dir() as output_dir: + # target python 3 + pex_out_path = os.path.join(output_dir, 'pex_py3.pex') + res = run_pex_command(['--disable-cache', + '--interpreter-constraint=>3', + '-o', pex_out_path]) + res.assert_success() + pex_info = get_pex_info(pex_out_path) + assert ['>3'] == pex_info.interpreter_constraints def test_interpreter_resolution_with_constraint_option(): @@ -497,61 +498,64 @@ def test_pex_exec_with_pex_python_path_and_pex_python_but_no_constraints(): assert str(pex_python_path.split(':')[0]).encode() in stdout -@pytest.mark.skip('https://github.com/pantsbuild/pex/issues/470') def test_pex_python(): - with temporary_dir() as td: - pexrc_path = os.path.join(td, '.pexrc') - with open(pexrc_path, 'w') as pexrc: - pex_python = ensure_python_interpreter('3.6.3') - pexrc.write("PEX_PYTHON=%s" % pex_python) - - # test PEX_PYTHON with valid constraints - pex_out_path = os.path.join(td, 'pex.pex') - res = run_pex_command(['--disable-cache', - '--rcfile=%s' % pexrc_path, - '--interpreter-constraint=>3', - '--interpreter-constraint=<3.8', - '-o', pex_out_path]) - res.assert_success() - - stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' - stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) - assert rc == 0 - correct_interpreter_path = pex_python.encode() - assert correct_interpreter_path in stdout - - # test PEX_PYTHON with incompatible constraints - pexrc_path = os.path.join(td, '.pexrc') - with open(pexrc_path, 'w') as pexrc: - pex_python = ensure_python_interpreter('2.7.10') - pexrc.write("PEX_PYTHON=%s" % pex_python) - - pex_out_path = os.path.join(td, 'pex2.pex') - res = run_pex_command(['--disable-cache', - '--rcfile=%s' % pexrc_path, - '--interpreter-constraint=>3', - '--interpreter-constraint=<3.8', - '-o', pex_out_path]) - res.assert_success() - - stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' - stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) - assert rc == 1 - fail_str = 'not compatible with specified interpreter constraints'.encode() - assert fail_str in stdout - - # test PEX_PYTHON with no constraints - pex_out_path = os.path.join(td, 'pex3.pex') - res = run_pex_command(['--disable-cache', - '--rcfile=%s' % pexrc_path, - '-o', pex_out_path]) - res.assert_success() + py2_path_interpreter = ensure_python_interpreter('2.7.10') + py3_path_interpreter = ensure_python_interpreter('3.6.3') + path = ':'.join([os.path.dirname(py2_path_interpreter), os.path.dirname(py3_path_interpreter)]) + with environment_as(PATH=path): + with temporary_dir() as td: + pexrc_path = os.path.join(td, '.pexrc') + with open(pexrc_path, 'w') as pexrc: + pex_python = ensure_python_interpreter('3.6.3') + pexrc.write("PEX_PYTHON=%s" % pex_python) + + # test PEX_PYTHON with valid constraints + pex_out_path = os.path.join(td, 'pex.pex') + res = run_pex_command(['--disable-cache', + '--rcfile=%s' % pexrc_path, + '--interpreter-constraint=>3', + '--interpreter-constraint=<3.8', + '-o', pex_out_path]) + res.assert_success() + + stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' + stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) + assert rc == 0 + correct_interpreter_path = pex_python.encode() + assert correct_interpreter_path in stdout - stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' - stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) - assert rc == 0 - correct_interpreter_path = pex_python.encode() - assert correct_interpreter_path in stdout + # test PEX_PYTHON with incompatible constraints + pexrc_path = os.path.join(td, '.pexrc') + with open(pexrc_path, 'w') as pexrc: + pex_python = ensure_python_interpreter('2.7.10') + pexrc.write("PEX_PYTHON=%s" % pex_python) + + pex_out_path = os.path.join(td, 'pex2.pex') + res = run_pex_command(['--disable-cache', + '--rcfile=%s' % pexrc_path, + '--interpreter-constraint=>3', + '--interpreter-constraint=<3.8', + '-o', pex_out_path]) + res.assert_success() + + stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' + stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) + assert rc == 1 + fail_str = 'not compatible with specified interpreter constraints'.encode() + assert fail_str in stdout + + # test PEX_PYTHON with no constraints + pex_out_path = os.path.join(td, 'pex3.pex') + res = run_pex_command(['--disable-cache', + '--rcfile=%s' % pexrc_path, + '-o', pex_out_path]) + res.assert_success() + + stdin_payload = b'import sys; print(sys.executable); sys.exit(0)' + stdout, rc = run_simple_pex(pex_out_path, stdin=stdin_payload) + assert rc == 0 + correct_interpreter_path = pex_python.encode() + assert correct_interpreter_path in stdout def test_entry_point_targeting():