def test_pants_test_interpreter_selection_with_pexrc(self): """Test the pants test goal with intepreters selected from a PEX_PYTHON_PATH defined in a pexrc file on disk. """ py27_path, py3_path = python_interpreter_path( PY_27), python_interpreter_path(PY_3) with setup_pexrc_with_pex_python_path([py27_path, py3_path]): with temporary_dir() as interpreters_cache: pants_ini_config = { 'python-setup': { 'interpreter_cache_dir': interpreters_cache } } pants_run_27 = self.run_pants(command=[ 'test', '{}:test_py2'.format( os.path.join(self.testproject, 'python_3_selection_testing')) ], config=pants_ini_config) self.assert_success(pants_run_27) pants_run_3 = self.run_pants(command=[ 'test', '{}:test_py3'.format( os.path.join(self.testproject, 'python_3_selection_testing')) ], config=pants_ini_config) self.assert_success(pants_run_3)
def test_pants_run_interpreter_selection_with_pexrc(self): py27_path, py3_path = python_interpreter_path( PY_27), python_interpreter_path(PY_3) with setup_pexrc_with_pex_python_path([py27_path, py3_path]): with temporary_dir() as interpreters_cache: pants_ini_config = { 'python-setup': { 'interpreter_cache_dir': interpreters_cache } } pants_run_27 = self.run_pants(command=[ 'run', '{}:main_py2'.format( os.path.join(self.testproject, 'python_3_selection_testing')) ], config=pants_ini_config) self.assert_success(pants_run_27) self.assertIn(py27_path, pants_run_27.stdout_data) pants_run_3 = self.run_pants(command=[ 'run', '{}:main_py3'.format( os.path.join(self.testproject, 'python_3_selection_testing')) ], config=pants_ini_config) self.assert_success(pants_run_3) self.assertIn(py3_path, pants_run_3.stdout_data)
def test_pants_binary_interpreter_selection_with_pexrc(self): py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3) with setup_pexrc_with_pex_python_path([py27_path, py3_path]): with temporary_dir() as interpreters_cache: pants_ini_config = {'python-setup': {'interpreter_cache_dir': interpreters_cache}} pants_run_27 = self.run_pants( command=['binary', '{}:main_py2'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_27) pants_run_3 = self.run_pants( command=['binary', '{}:main_py3'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_3) # Ensure proper interpreter constraints were passed to built pexes. py2_pex = os.path.join(os.getcwd(), 'dist', 'main_py2.pex') py3_pex = os.path.join(os.getcwd(), 'dist', 'main_py3.pex') py2_info = PexInfo.from_pex(py2_pex) py3_info = PexInfo.from_pex(py3_pex) self.assertIn('CPython>2.7.6,<3', py2_info.interpreter_constraints) self.assertIn('CPython>3', py3_info.interpreter_constraints) # Cleanup created pexes. os.remove(py2_pex) os.remove(py3_pex)
def test_pants_test_interpreter_selection_with_pexrc(self): """Test the pants test goal with intepreters selected from a PEX_PYTHON_PATH defined in a pexrc file on disk. """ py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3) with setup_pexrc_with_pex_python_path([py27_path, py3_path]): with temporary_dir() as interpreters_cache: pants_ini_config = { 'python-setup': { 'interpreter_cache_dir': interpreters_cache, 'interpreter_search_paths': ['<PEXRC>'], } } pants_run_27 = self.run_pants( command=['test', '{}:test_py2'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_27) pants_run_3 = self.run_pants( command=['test', '{}:test_py3'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_3)
def test_pex_python_paths(self): """Test pex python path helper method of PythonInterpreterCache.""" py27_path, py36_path = python_interpreter_path(PY_27), python_interpreter_path(PY_36) with setup_pexrc_with_pex_python_path([py27_path, py36_path]): with self._setup_cache() as (cache, _): pex_python_paths = cache.pex_python_paths() self.assertEqual(pex_python_paths, [py27_path, py36_path])
def test_interpereter_cache_setup_using_pex_python_paths(self): """Test cache setup using interpreters from a mocked PEX_PYTHON_PATH.""" py27_path, py36_path = python_interpreter_path(PY_27), python_interpreter_path(PY_36) with setup_pexrc_with_pex_python_path([py27_path, py36_path]): with self._setup_cache(constraints=['CPython>=2.7,<3']) as (cache, _): self.assertIn(py27_path, {pi.binary for pi in cache.setup()}) with self._setup_cache(constraints=['CPython>=3.6,<4']) as (cache, _): self.assertIn(py36_path, {pi.binary for pi in cache.setup()})
def test_interpereter_cache_setup_using_pex_python_paths(self): """Test cache setup using interpreters from a mocked PEX_PYTHON_PATH.""" py27_path, py36_path = python_interpreter_path(PY_27), python_interpreter_path(PY_36) with setup_pexrc_with_pex_python_path([py27_path, py36_path]): with self._setup_cache(constraints=['CPython>=2.7,<3'], search_paths=['<PEXRC>']) as (cache, _): self.assertIn(py27_path, {pi.binary for pi in cache.setup()}) with self._setup_cache(constraints=['CPython>=3.6,<4'], search_paths=['<PEXRC>']) as (cache, _): self.assertIn(py36_path, {pi.binary for pi in cache.setup()})
def test_pants_run_interpreter_selection_with_pexrc(self): py27_path, py3_path = python_interpreter_path(PY_27), python_interpreter_path(PY_3) with setup_pexrc_with_pex_python_path([py27_path, py3_path]): with temporary_dir() as interpreters_cache: pants_ini_config = {'python-setup': {'interpreter_cache_dir': interpreters_cache}} pants_run_27 = self.run_pants( command=['run', '{}:main_py2'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_27) self.assertIn(py27_path, pants_run_27.stdout_data) pants_run_3 = self.run_pants( command=['run', '{}:main_py3'.format(os.path.join(self.testproject, 'python_3_selection_testing'))], config=pants_ini_config ) self.assert_success(pants_run_3) self.assertIn(py3_path, pants_run_3.stdout_data)