@@ -154,17 +154,47 @@ def test_symlinking(self):
154154 """
155155 for usl in (False , True ):
156156 builder = venv .EnvBuilder (clear = True , symlinks = usl )
157- if (usl and sys .platform == 'darwin' and
158- '__PYVENV_LAUNCHER__' in os .environ ):
159- self .assertRaises (ValueError , builder .create , self .env_dir )
160- else :
161- builder .create (self .env_dir )
162- fn = self .get_env_file (self .bindir , self .exe )
163- # Don't test when False, because e.g. 'python' is always
164- # symlinked to 'python3.3' in the env, even when symlinking in
165- # general isn't wanted.
166- if usl :
167- self .assertTrue (os .path .islink (fn ))
157+ builder .create (self .env_dir )
158+ fn = self .get_env_file (self .bindir , self .exe )
159+ # Don't test when False, because e.g. 'python' is always
160+ # symlinked to 'python3.3' in the env, even when symlinking in
161+ # general isn't wanted.
162+ if usl :
163+ self .assertTrue (os .path .islink (fn ))
164+
165+ # If a venv is created from a source build and that venv is used to
166+ # run the test, the pyvenv.cfg in the venv created in the test will
167+ # point to the venv being used to run the test, and we lose the link
168+ # to the source build - so Python can't initialise properly.
169+ @unittest .skipIf (sys .prefix != sys .base_prefix , 'Test not appropriate '
170+ 'in a venv' )
171+ def test_executable (self ):
172+ """
173+ Test that the sys.executable value is as expected.
174+ """
175+ shutil .rmtree (self .env_dir )
176+ self .run_with_capture (venv .create , self .env_dir )
177+ envpy = os .path .join (os .path .realpath (self .env_dir ), self .bindir , self .exe )
178+ cmd = [envpy , '-c' , 'import sys; print(sys.executable)' ]
179+ p = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
180+ stderr = subprocess .PIPE )
181+ out , err = p .communicate ()
182+ self .assertEqual (out [:- 1 ], envpy .encode ())
183+
184+ @unittest .skipUnless (can_symlink (), 'Needs symlinks' )
185+ def test_executable_symlinks (self ):
186+ """
187+ Test that the sys.executable value is as expected.
188+ """
189+ shutil .rmtree (self .env_dir )
190+ builder = venv .EnvBuilder (clear = True , symlinks = True )
191+ builder .create (self .env_dir )
192+ envpy = os .path .join (os .path .realpath (self .env_dir ), self .bindir , self .exe )
193+ cmd = [envpy , '-c' , 'import sys; print(sys.executable)' ]
194+ p = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
195+ stderr = subprocess .PIPE )
196+ out , err = p .communicate ()
197+ self .assertEqual (out [:- 1 ], envpy .encode ())
168198
169199def test_main ():
170200 run_unittest (BasicTest )
0 commit comments