|
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) |
@@ -136,20 +142,16 @@ def test_prefixes(self): |
136 | 142 | """ |
137 | 143 | Test that the prefix values are as expected. |
138 | 144 | """ |
139 | | - #check our prefixes |
140 | | - self.assertEqual(sys.base_prefix, sys.prefix) |
141 | | - self.assertEqual(sys.base_exec_prefix, sys.exec_prefix) |
142 | | - |
143 | 145 | # check a venv's prefixes |
144 | 146 | rmtree(self.env_dir) |
145 | 147 | self.run_with_capture(venv.create, self.env_dir) |
146 | 148 | envpy = os.path.join(self.env_dir, self.bindir, self.exe) |
147 | 149 | cmd = [envpy, '-c', None] |
148 | 150 | for prefix, expected in ( |
149 | 151 | ('prefix', self.env_dir), |
150 | | - ('prefix', self.env_dir), |
151 | | - ('base_prefix', sys.prefix), |
152 | | - ('base_exec_prefix', sys.exec_prefix)): |
| 152 | + ('exec_prefix', self.env_dir), |
| 153 | + ('base_prefix', sys.base_prefix), |
| 154 | + ('base_exec_prefix', sys.base_exec_prefix)): |
153 | 155 | cmd[2] = 'import sys; print(sys.%s)' % prefix |
154 | 156 | out, err = check_output(cmd) |
155 | 157 | self.assertEqual(out.strip(), expected.encode()) |
@@ -261,7 +263,12 @@ def test_symlinking(self): |
261 | 263 | # symlinked to 'python3.3' in the env, even when symlinking in |
262 | 264 | # general isn't wanted. |
263 | 265 | if usl: |
264 | | - self.assertTrue(os.path.islink(fn)) |
| 266 | + if self.cannot_link_exe: |
| 267 | + # Symlinking is skipped when our executable is already a |
| 268 | + # special app symlink |
| 269 | + self.assertFalse(os.path.islink(fn)) |
| 270 | + else: |
| 271 | + self.assertTrue(os.path.islink(fn)) |
265 | 272 |
|
266 | 273 | # If a venv is created from a source build and that venv is used to |
267 | 274 | # run the test, the pyvenv.cfg in the venv created in the test will |
|
0 commit comments