Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(90243)

Side by Side Diff: Lib/test/test_venv.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_uuid.py ('k') | Lib/test/test_webbrowser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 Test harness for the venv module. 2 Test harness for the venv module.
3 3
4 Copyright (C) 2011-2012 Vinay Sajip. 4 Copyright (C) 2011-2012 Vinay Sajip.
5 Licensed to the PSF under a contributor agreement. 5 Licensed to the PSF under a contributor agreement.
6 """ 6 """
7 7
8 import ensurepip 8 import ensurepip
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 path = os.path.dirname(executable) 109 path = os.path.dirname(executable)
110 self.assertIn('home = %s' % path, data) 110 self.assertIn('home = %s' % path, data)
111 fn = self.get_env_file(self.bindir, self.exe) 111 fn = self.get_env_file(self.bindir, self.exe)
112 if not os.path.exists(fn): # diagnostics for Windows buildbot failures 112 if not os.path.exists(fn): # diagnostics for Windows buildbot failures
113 bd = self.get_env_file(self.bindir) 113 bd = self.get_env_file(self.bindir)
114 print('Contents of %r:' % bd) 114 print('Contents of %r:' % bd)
115 print(' %r' % os.listdir(bd)) 115 print(' %r' % os.listdir(bd))
116 self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn) 116 self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn)
117 117
118 @skipInVenv 118 @skipInVenv
119 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess .Popen()")
119 def test_prefixes(self): 120 def test_prefixes(self):
120 """ 121 """
121 Test that the prefix values are as expected. 122 Test that the prefix values are as expected.
122 """ 123 """
123 #check our prefixes 124 #check our prefixes
124 self.assertEqual(sys.base_prefix, sys.prefix) 125 self.assertEqual(sys.base_prefix, sys.prefix)
125 self.assertEqual(sys.base_exec_prefix, sys.exec_prefix) 126 self.assertEqual(sys.base_exec_prefix, sys.exec_prefix)
126 127
127 # check a venv's prefixes 128 # check a venv's prefixes
128 rmtree(self.env_dir) 129 rmtree(self.env_dir)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 # symlinked to 'python3.3' in the env, even when symlinking in 248 # symlinked to 'python3.3' in the env, even when symlinking in
248 # general isn't wanted. 249 # general isn't wanted.
249 if usl: 250 if usl:
250 self.assertTrue(os.path.islink(fn)) 251 self.assertTrue(os.path.islink(fn))
251 252
252 # If a venv is created from a source build and that venv is used to 253 # If a venv is created from a source build and that venv is used to
253 # run the test, the pyvenv.cfg in the venv created in the test will 254 # run the test, the pyvenv.cfg in the venv created in the test will
254 # point to the venv being used to run the test, and we lose the link 255 # point to the venv being used to run the test, and we lose the link
255 # to the source build - so Python can't initialise properly. 256 # to the source build - so Python can't initialise properly.
256 @skipInVenv 257 @skipInVenv
258 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess .Popen()")
257 def test_executable(self): 259 def test_executable(self):
258 """ 260 """
259 Test that the sys.executable value is as expected. 261 Test that the sys.executable value is as expected.
260 """ 262 """
261 rmtree(self.env_dir) 263 rmtree(self.env_dir)
262 self.run_with_capture(venv.create, self.env_dir) 264 self.run_with_capture(venv.create, self.env_dir)
263 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.e xe) 265 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.e xe)
264 cmd = [envpy, '-c', 'import sys; print(sys.executable)'] 266 cmd = [envpy, '-c', 'import sys; print(sys.executable)']
265 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, 267 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
266 stderr=subprocess.PIPE) 268 stderr=subprocess.PIPE)
267 out, err = p.communicate() 269 out, err = p.communicate()
268 self.assertEqual(out.strip(), envpy.encode()) 270 self.assertEqual(out.strip(), envpy.encode())
269 271
270 @unittest.skipUnless(can_symlink(), 'Needs symlinks') 272 @unittest.skipUnless(can_symlink(), 'Needs symlinks')
273 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess .Popen()")
271 def test_executable_symlinks(self): 274 def test_executable_symlinks(self):
272 """ 275 """
273 Test that the sys.executable value is as expected. 276 Test that the sys.executable value is as expected.
274 """ 277 """
275 rmtree(self.env_dir) 278 rmtree(self.env_dir)
276 builder = venv.EnvBuilder(clear=True, symlinks=True) 279 builder = venv.EnvBuilder(clear=True, symlinks=True)
277 builder.create(self.env_dir) 280 builder.create(self.env_dir)
278 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.e xe) 281 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.e xe)
279 cmd = [envpy, '-c', 'import sys; print(sys.executable)'] 282 cmd = [envpy, '-c', 'import sys; print(sys.executable)']
280 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, 283 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
281 stderr=subprocess.PIPE) 284 stderr=subprocess.PIPE)
282 out, err = p.communicate() 285 out, err = p.communicate()
283 self.assertEqual(out.strip(), envpy.encode()) 286 self.assertEqual(out.strip(), envpy.encode())
284 287
285 288
286 @skipInVenv 289 @skipInVenv
287 class EnsurePipTest(BaseTest): 290 class EnsurePipTest(BaseTest):
288 """Test venv module installation of pip.""" 291 """Test venv module installation of pip."""
292 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess .Popen()")
289 def assert_pip_not_installed(self): 293 def assert_pip_not_installed(self):
290 envpy = os.path.join(os.path.realpath(self.env_dir), 294 envpy = os.path.join(os.path.realpath(self.env_dir),
291 self.bindir, self.exe) 295 self.bindir, self.exe)
292 try_import = 'try:\n import pip\nexcept ImportError:\n print("OK")' 296 try_import = 'try:\n import pip\nexcept ImportError:\n print("OK")'
293 cmd = [envpy, '-c', try_import] 297 cmd = [envpy, '-c', try_import]
294 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, 298 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
295 stderr=subprocess.PIPE) 299 stderr=subprocess.PIPE)
296 out, err = p.communicate() 300 out, err = p.communicate()
297 # We force everything to text, so unittest gives the detailed diff 301 # We force everything to text, so unittest gives the detailed diff
298 # if we get unexpected results 302 # if we get unexpected results
(...skipping 18 matching lines...) Expand all
317 # Fix for issue #20053 uses os.devnull to force a config file to 321 # Fix for issue #20053 uses os.devnull to force a config file to
318 # appear empty. However http://bugs.python.org/issue20541 means 322 # appear empty. However http://bugs.python.org/issue20541 means
319 # that doesn't currently work properly on Windows. Once that is 323 # that doesn't currently work properly on Windows. Once that is
320 # fixed, the "win_location" part of test_with_pip should be restored 324 # fixed, the "win_location" part of test_with_pip should be restored
321 self.assertTrue(os.path.exists(os.devnull)) 325 self.assertTrue(os.path.exists(os.devnull))
322 with open(os.devnull, "rb") as f: 326 with open(os.devnull, "rb") as f:
323 self.assertEqual(f.read(), b"") 327 self.assertEqual(f.read(), b"")
324 328
325 # Requesting pip fails without SSL (http://bugs.python.org/issue19744) 329 # Requesting pip fails without SSL (http://bugs.python.org/issue19744)
326 @unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE) 330 @unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE)
331 @unittest.skipUnless(hasattr(subprocess, 'Popen'), "test requires subprocess .Popen()")
327 @unittest.skipUnless(threading, 'some dependencies of pip import threading' 332 @unittest.skipUnless(threading, 'some dependencies of pip import threading'
328 ' module unconditionally') 333 ' module unconditionally')
329 def test_with_pip(self): 334 def test_with_pip(self):
330 rmtree(self.env_dir) 335 rmtree(self.env_dir)
331 with EnvironmentVarGuard() as envvars: 336 with EnvironmentVarGuard() as envvars:
332 # pip's cross-version compatibility may trigger deprecation 337 # pip's cross-version compatibility may trigger deprecation
333 # warnings in current versions of Python. Ensure related 338 # warnings in current versions of Python. Ensure related
334 # environment settings don't cause venv to fail. 339 # environment settings don't cause venv to fail.
335 envvars["PYTHONWARNINGS"] = "e" 340 envvars["PYTHONWARNINGS"] = "e"
336 # ensurepip is different enough from a normal pip invocation 341 # ensurepip is different enough from a normal pip invocation
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 # future pip versions, this test can likely be relaxed further. 405 # future pip versions, this test can likely be relaxed further.
401 out = out.decode("latin-1") # Force to text, prevent decoding errors 406 out = out.decode("latin-1") # Force to text, prevent decoding errors
402 self.assertIn("Successfully uninstalled pip", out) 407 self.assertIn("Successfully uninstalled pip", out)
403 self.assertIn("Successfully uninstalled setuptools", out) 408 self.assertIn("Successfully uninstalled setuptools", out)
404 # Check pip is now gone from the virtual environment 409 # Check pip is now gone from the virtual environment
405 self.assert_pip_not_installed() 410 self.assert_pip_not_installed()
406 411
407 412
408 if __name__ == "__main__": 413 if __name__ == "__main__":
409 unittest.main() 414 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_uuid.py ('k') | Lib/test/test_webbrowser.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+