|
28 | 28 | # Platforms that set sys._base_executable can create venvs from within |
29 | 29 | # another venv, so no need to skip tests that require venv.create(). |
30 | 30 | requireVenvCreate = unittest.skipUnless( |
31 | | - hasattr(sys, '_base_executable') |
32 | | - or sys.prefix == sys.base_prefix, |
| 31 | + sys.prefix == sys.base_prefix |
| 32 | + or sys._base_executable != sys.executable, |
33 | 33 | 'cannot run venv.create from within a venv on this platform') |
34 | 34 |
|
35 | 35 | def check_output(cmd, encoding=None): |
@@ -57,8 +57,14 @@ def setUp(self): |
57 | 57 | self.bindir = 'bin' |
58 | 58 | self.lib = ('lib', 'python%d.%d' % sys.version_info[:2]) |
59 | 59 | self.include = 'include' |
60 | | - executable = getattr(sys, '_base_executable', sys.executable) |
| 60 | + executable = sys._base_executable |
61 | 61 | self.exe = os.path.split(executable)[-1] |
| 62 | + if (sys.platform == 'win32' |
| 63 | + and os.path.lexists(executable) |
| 64 | + and not os.path.exists(executable)): |
| 65 | + self.cannot_link_exe = True |
| 66 | + else: |
| 67 | + self.cannot_link_exe = False |
62 | 68 |
|
63 | 69 | def tearDown(self): |
64 | 70 | rmtree(self.env_dir) |
@@ -102,7 +108,7 @@ def test_defaults(self): |
102 | 108 | else: |
103 | 109 | self.assertFalse(os.path.exists(p)) |
104 | 110 | data = self.get_text_file_contents('pyvenv.cfg') |
105 | | - executable = getattr(sys, '_base_executable', sys.executable) |
| 111 | + executable = sys._base_executable |
106 | 112 | path = os.path.dirname(executable) |
107 | 113 | self.assertIn('home = %s' % path, data) |
108 | 114 | fn = self.get_env_file(self.bindir, self.exe) |
@@ -158,20 +164,16 @@ def test_prefixes(self): |
158 | 164 | """ |
159 | 165 | Test that the prefix values are as expected. |
160 | 166 | """ |
161 | | - #check our prefixes |
162 | | - self.assertEqual(sys.base_prefix, sys.prefix) |
163 | | - self.assertEqual(sys.base_exec_prefix, sys.exec_prefix) |
164 | | - |
165 | 167 | # check a venv's prefixes |
166 | 168 | rmtree(self.env_dir) |
167 | 169 | self.run_with_capture(venv.create, self.env_dir) |
168 | 170 | envpy = os.path.join(self.env_dir, self.bindir, self.exe) |
169 | 171 | cmd = [envpy, '-c', None] |
170 | 172 | for prefix, expected in ( |
171 | 173 | ('prefix', self.env_dir), |
172 | | - ('prefix', self.env_dir), |
173 | | - ('base_prefix', sys.prefix), |
174 | | - ('base_exec_prefix', sys.exec_prefix)): |
| 174 | + ('exec_prefix', self.env_dir), |
| 175 | + ('base_prefix', sys.base_prefix), |
| 176 | + ('base_exec_prefix', sys.base_exec_prefix)): |
175 | 177 | cmd[2] = 'import sys; print(sys.%s)' % prefix |
176 | 178 | out, err = check_output(cmd) |
177 | 179 | self.assertEqual(out.strip(), expected.encode()) |
@@ -283,7 +285,12 @@ def test_symlinking(self): |
283 | 285 | # symlinked to 'python3.3' in the env, even when symlinking in |
284 | 286 | # general isn't wanted. |
285 | 287 | if usl: |
286 | | - self.assertTrue(os.path.islink(fn)) |
| 288 | + if self.cannot_link_exe: |
| 289 | + # Symlinking is skipped when our executable is already a |
| 290 | + # special app symlink |
| 291 | + self.assertFalse(os.path.islink(fn)) |
| 292 | + else: |
| 293 | + self.assertTrue(os.path.islink(fn)) |
287 | 294 |
|
288 | 295 | # If a venv is created from a source build and that venv is used to |
289 | 296 | # run the test, the pyvenv.cfg in the venv created in the test will |
|
0 commit comments