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>'],
                 },
                 **self.pytest_setup_for_python_2_tests,
             }
             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)
Exemplo n.º 2
0
    def test_expand_interpreter_search_paths(self):

        local_pyenv_version = "3.5.5"
        all_pyenv_versions = ["2.7.14", local_pyenv_version]
        self.create_file(".python-version", local_pyenv_version + "\n")
        with environment_as(PATH="/env/path1:/env/path2"):
            with setup_pexrc_with_pex_python_path(
                ["/pexrc/path1:/pexrc/path2"]):
                with fake_pyenv_root(all_pyenv_versions,
                                     local_pyenv_version) as (
                                         pyenv_root,
                                         expected_pyenv_paths,
                                         expected_pyenv_local_paths,
                                     ):
                    paths = [
                        "/foo",
                        "<PATH>",
                        "/bar",
                        "<PEXRC>",
                        "/baz",
                        "<PYENV>",
                        "<PYENV_LOCAL>",
                        "/qux",
                    ]
                    expanded_paths = PythonSetup.expand_interpreter_search_paths(
                        paths, pyenv_root_func=lambda: pyenv_root)

        expected = ([
            "/foo", "/env/path1", "/env/path2", "/bar", "/pexrc/path1",
            "/pexrc/path2", "/baz"
        ] + expected_pyenv_paths + expected_pyenv_local_paths + ["/qux"])
        self.assertListEqual(expected, expanded_paths)
  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)
Exemplo n.º 4
0
 def test_pants_test_interpreter_selection_with_pexrc(self):
     """Test the pants test goal with interpreters 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>"],
                 },
                 **self.pytest_setup_for_python_2_tests,
             }
             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)
Exemplo n.º 5
0
 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("I am a python 2 library method.",
                           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("I am a python 3 library method.",
                           pants_run_3.stdout_data)
 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('I am a python 2 library method.',
                           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('I am a python 3 library method.',
                           pants_run_3.stdout_data)
Exemplo n.º 7
0
 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()})
Exemplo n.º 8
0
    def test_expand_interpreter_search_paths(self):
        with environment_as(PATH="/env/path1:/env/path2"):
            with setup_pexrc_with_pex_python_path(
                ["/pexrc/path1:/pexrc/path2"]):
                with fake_pyenv_root(["2.7.14", "3.5.5"
                                      ]) as (pyenv_root, expected_pyenv_paths):
                    paths = [
                        "/foo", "<PATH>", "/bar", "<PEXRC>", "/baz", "<PYENV>",
                        "/qux"
                    ]
                    expanded_paths = PythonSetup.expand_interpreter_search_paths(
                        paths, pyenv_root_func=lambda: pyenv_root)

        expected = ([
            "/foo", "/env/path1", "/env/path2", "/bar", "/pexrc/path1",
            "/pexrc/path2", "/baz"
        ] + expected_pyenv_paths + ["/qux"])
        self.assertListEqual(expected, expanded_paths)
Exemplo n.º 9
0
    def test_expand_interpreter_search_paths(self):
        with environment_as(PATH='/env/path1:/env/path2'):
            with setup_pexrc_with_pex_python_path(
                ['/pexrc/path1:/pexrc/path2']):
                with fake_pyenv_root(['2.7.14', '3.5.5'
                                      ]) as (pyenv_root, expected_pyenv_paths):
                    paths = [
                        '/foo', '<PATH>', '/bar', '<PEXRC>', '/baz', '<PYENV>',
                        '/qux'
                    ]
                    expanded_paths = PythonSetup.expand_interpreter_search_paths(
                        paths, pyenv_root_func=lambda: pyenv_root)

        expected = [
            '/foo', '/env/path1', '/env/path2', '/bar', '/pexrc/path1',
            '/pexrc/path2', '/baz'
        ] + expected_pyenv_paths + ['/qux']
        self.assertListEqual(expected, expanded_paths)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
 def test_get_pex_python_paths(self):
     with setup_pexrc_with_pex_python_path(["foo/bar", "baz", "/qux/quux"]):
         paths = PythonSetup.get_pex_python_paths()
     self.assertListEqual(["foo/bar", "baz", "/qux/quux"], paths)
Exemplo n.º 12
0
 def test_get_pex_python_paths(self):
     with setup_pexrc_with_pex_python_path(['foo/bar', 'baz', '/qux/quux']):
         paths = PythonSetup.get_pex_python_paths()
     self.assertListEqual(['foo/bar', 'baz', '/qux/quux'], paths)
Exemplo n.º 13
0
 def test_get_pex_python_paths(self):
     with setup_pexrc_with_pex_python_path(["foo/bar", "baz", "/qux/quux"]):
         paths = PythonSetup.get_pex_python_paths()
     assert ["foo/bar", "baz", "/qux/quux"] == paths