diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_venv.py | 52 | ||||
-rw-r--r-- | Lib/venv/__init__.py | 10 |
2 files changed, 42 insertions, 20 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 6f73fcf..b1b831e 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -154,17 +154,47 @@ class BasicTest(BaseTest): """ for usl in (False, True): builder = venv.EnvBuilder(clear=True, symlinks=usl) - if (usl and sys.platform == 'darwin' and - '__PYVENV_LAUNCHER__' in os.environ): - self.assertRaises(ValueError, builder.create, self.env_dir) - else: - builder.create(self.env_dir) - fn = self.get_env_file(self.bindir, self.exe) - # Don't test when False, because e.g. 'python' is always - # symlinked to 'python3.3' in the env, even when symlinking in - # general isn't wanted. - if usl: - self.assertTrue(os.path.islink(fn)) + builder.create(self.env_dir) + fn = self.get_env_file(self.bindir, self.exe) + # Don't test when False, because e.g. 'python' is always + # symlinked to 'python3.3' in the env, even when symlinking in + # general isn't wanted. + if usl: + self.assertTrue(os.path.islink(fn)) + + # If a venv is created from a source build and that venv is used to + # run the test, the pyvenv.cfg in the venv created in the test will + # point to the venv being used to run the test, and we lose the link + # to the source build - so Python can't initialise properly. + @unittest.skipIf(sys.prefix != sys.base_prefix, 'Test not appropriate ' + 'in a venv') + def test_executable(self): + """ + Test that the sys.executable value is as expected. + """ + shutil.rmtree(self.env_dir) + self.run_with_capture(venv.create, self.env_dir) + envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe) + cmd = [envpy, '-c', 'import sys; print(sys.executable)'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = p.communicate() + self.assertEqual(out[:-1], envpy.encode()) + + @unittest.skipUnless(can_symlink(), 'Needs symlinks') + def test_executable_symlinks(self): + """ + Test that the sys.executable value is as expected. + """ + shutil.rmtree(self.env_dir) + builder = venv.EnvBuilder(clear=True, symlinks=True) + builder.create(self.env_dir) + envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe) + cmd = [envpy, '-c', 'import sys; print(sys.executable)'] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, err = p.communicate() + self.assertEqual(out[:-1], envpy.encode()) def test_main(): run_unittest(BasicTest) diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py index 38ed54c..8d2deb7 100644 --- a/Lib/venv/__init__.py +++ b/Lib/venv/__init__.py @@ -82,13 +82,6 @@ class EnvBuilder: :param env_dir: The target directory to create an environment in. """ - if (self.symlinks and - sys.platform == 'darwin' and - sysconfig.get_config_var('PYTHONFRAMEWORK')): - # Symlinking the stub executable in an OSX framework build will - # result in a broken virtual environment. - raise ValueError( - 'Symlinking is not supported on OSX framework Python.') env_dir = os.path.abspath(env_dir) context = self.ensure_directories(env_dir) self.create_configuration(context) @@ -366,8 +359,7 @@ def main(args=None): action='store_true', dest='system_site', help='Give the virtual environment access to the ' 'system site-packages dir.') - if os.name == 'nt' or (sys.platform == 'darwin' and - sysconfig.get_config_var('PYTHONFRAMEWORK')): + if os.name == 'nt': use_symlinks = False else: use_symlinks = True |