blob: 3999d1f9c40ffd291ab3ca51e294ef3f46c1c354 [file] [log] [blame]
Vinay Sajip42211422012-05-26 20:36:12 +01001"""
2Test harness for the venv module.
Vinay Sajip7ded1f02012-05-26 03:45:29 +01003
Vinay Sajip42211422012-05-26 20:36:12 +01004Copyright (C) 2011-2012 Vinay Sajip.
Vinay Sajip28952442012-06-25 00:47:46 +01005Licensed to the PSF under a contributor agreement.
Vinay Sajip7ded1f02012-05-26 03:45:29 +01006"""
7
Nick Coghlan1b1b1782013-11-30 15:56:58 +10008import ensurepip
Vinay Sajip7ded1f02012-05-26 03:45:29 +01009import os
10import os.path
Victor Stinner87d6e132016-03-14 18:21:58 +010011import re
Vinay Sajip1e53f8d2014-04-15 11:18:10 +010012import struct
Vinay Sajip3874e542012-07-03 16:56:40 +010013import subprocess
Vinay Sajip7ded1f02012-05-26 03:45:29 +010014import sys
15import tempfile
Zachary Ware38c707e2015-04-13 15:00:43 -050016from test.support import (captured_stdout, captured_stderr,
Victor Stinner866c4e22014-10-10 14:23:00 +020017 can_symlink, EnvironmentVarGuard, rmtree)
Nick Coghlanfdf3a622013-11-30 17:15:09 +100018import textwrap
Vinay Sajip7ded1f02012-05-26 03:45:29 +010019import unittest
20import venv
Nick Coghlanae2ee962013-12-23 23:07:07 +100021
22# pip currently requires ssl support, so we ensure we handle
23# it being missing (http://bugs.python.org/issue19744)
Nick Coghlan878d2582013-11-24 12:45:25 +100024try:
25 import ssl
26except ImportError:
27 ssl = None
Vinay Sajip7ded1f02012-05-26 03:45:29 +010028
Berker Peksag1b25eff2016-01-19 02:01:53 +020029try:
30 import threading
31except ImportError:
32 threading = None
33
Berker Peksag5a5ae742016-09-18 14:52:25 +030034try:
35 import ctypes
36except ImportError:
37 ctypes = None
38
Nick Coghlan8fbdb092013-11-23 00:30:34 +100039skipInVenv = unittest.skipIf(sys.prefix != sys.base_prefix,
40 'Test not appropriate in a venv')
41
Nick Coghlan11c5afd2014-02-07 23:46:38 +100042# os.path.exists('nul') is False: http://bugs.python.org/issue20541
43if os.devnull.lower() == 'nul':
44 failsOnWindows = unittest.expectedFailure
45else:
46 def failsOnWindows(f):
47 return f
Nick Coghlan8fbdb092013-11-23 00:30:34 +100048
Vinay Sajip7ded1f02012-05-26 03:45:29 +010049class BaseTest(unittest.TestCase):
50 """Base class for venv tests."""
51
52 def setUp(self):
Ned Deily045bd532012-07-13 15:48:04 -070053 self.env_dir = os.path.realpath(tempfile.mkdtemp())
Vinay Sajip7ded1f02012-05-26 03:45:29 +010054 if os.name == 'nt':
55 self.bindir = 'Scripts'
Vinay Sajip7ded1f02012-05-26 03:45:29 +010056 self.lib = ('Lib',)
57 self.include = 'Include'
Vinay Sajip7ded1f02012-05-26 03:45:29 +010058 else:
59 self.bindir = 'bin'
Vinay Sajip7ded1f02012-05-26 03:45:29 +010060 self.lib = ('lib', 'python%s' % sys.version[:3])
61 self.include = 'include'
Vinay Sajip28952442012-06-25 00:47:46 +010062 if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in os.environ:
63 executable = os.environ['__PYVENV_LAUNCHER__']
Vinay Sajip382a7c02012-05-28 16:34:47 +010064 else:
65 executable = sys.executable
66 self.exe = os.path.split(executable)[-1]
Vinay Sajip7ded1f02012-05-26 03:45:29 +010067
68 def tearDown(self):
Victor Stinner866c4e22014-10-10 14:23:00 +020069 rmtree(self.env_dir)
Vinay Sajip7ded1f02012-05-26 03:45:29 +010070
71 def run_with_capture(self, func, *args, **kwargs):
72 with captured_stdout() as output:
73 with captured_stderr() as error:
74 func(*args, **kwargs)
75 return output.getvalue(), error.getvalue()
76
77 def get_env_file(self, *args):
78 return os.path.join(self.env_dir, *args)
79
80 def get_text_file_contents(self, *args):
81 with open(self.get_env_file(*args), 'r') as f:
82 result = f.read()
83 return result
84
85class BasicTest(BaseTest):
86 """Test venv module functionality."""
87
Vinay Sajipb3b49cd2012-05-27 18:39:22 +010088 def isdir(self, *args):
89 fn = self.get_env_file(*args)
90 self.assertTrue(os.path.isdir(fn))
91
Vinay Sajip7ded1f02012-05-26 03:45:29 +010092 def test_defaults(self):
93 """
94 Test the create function with default arguments.
95 """
Victor Stinner866c4e22014-10-10 14:23:00 +020096 rmtree(self.env_dir)
Vinay Sajip7ded1f02012-05-26 03:45:29 +010097 self.run_with_capture(venv.create, self.env_dir)
Vinay Sajipb3b49cd2012-05-27 18:39:22 +010098 self.isdir(self.bindir)
99 self.isdir(self.include)
100 self.isdir(*self.lib)
Vinay Sajip1e53f8d2014-04-15 11:18:10 +0100101 # Issue 21197
102 p = self.get_env_file('lib64')
103 conditions = ((struct.calcsize('P') == 8) and (os.name == 'posix') and
104 (sys.platform != 'darwin'))
105 if conditions:
106 self.assertTrue(os.path.islink(p))
107 else:
108 self.assertFalse(os.path.exists(p))
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100109 data = self.get_text_file_contents('pyvenv.cfg')
Vinay Sajip28952442012-06-25 00:47:46 +0100110 if sys.platform == 'darwin' and ('__PYVENV_LAUNCHER__'
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100111 in os.environ):
Vinay Sajip28952442012-06-25 00:47:46 +0100112 executable = os.environ['__PYVENV_LAUNCHER__']
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100113 else:
114 executable = sys.executable
115 path = os.path.dirname(executable)
116 self.assertIn('home = %s' % path, data)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100117 fn = self.get_env_file(self.bindir, self.exe)
Vinay Sajip7e203492012-05-27 17:30:09 +0100118 if not os.path.exists(fn): # diagnostics for Windows buildbot failures
Vinay Sajipb3b49cd2012-05-27 18:39:22 +0100119 bd = self.get_env_file(self.bindir)
120 print('Contents of %r:' % bd)
121 print(' %r' % os.listdir(bd))
Vinay Sajip7e203492012-05-27 17:30:09 +0100122 self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100123
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000124 @skipInVenv
Vinay Sajip3874e542012-07-03 16:56:40 +0100125 def test_prefixes(self):
126 """
127 Test that the prefix values are as expected.
128 """
129 #check our prefixes
130 self.assertEqual(sys.base_prefix, sys.prefix)
131 self.assertEqual(sys.base_exec_prefix, sys.exec_prefix)
132
133 # check a venv's prefixes
Victor Stinner866c4e22014-10-10 14:23:00 +0200134 rmtree(self.env_dir)
Vinay Sajip3874e542012-07-03 16:56:40 +0100135 self.run_with_capture(venv.create, self.env_dir)
136 envpy = os.path.join(self.env_dir, self.bindir, self.exe)
137 cmd = [envpy, '-c', None]
138 for prefix, expected in (
139 ('prefix', self.env_dir),
140 ('prefix', self.env_dir),
141 ('base_prefix', sys.prefix),
142 ('base_exec_prefix', sys.exec_prefix)):
143 cmd[2] = 'import sys; print(sys.%s)' % prefix
144 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
145 stderr=subprocess.PIPE)
146 out, err = p.communicate()
Antoine Pitrou9c92a692012-08-05 00:33:10 +0200147 self.assertEqual(out.strip(), expected.encode())
Vinay Sajip3874e542012-07-03 16:56:40 +0100148
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100149 if sys.platform == 'win32':
150 ENV_SUBDIRS = (
151 ('Scripts',),
152 ('Include',),
153 ('Lib',),
154 ('Lib', 'site-packages'),
155 )
156 else:
157 ENV_SUBDIRS = (
158 ('bin',),
159 ('include',),
160 ('lib',),
161 ('lib', 'python%d.%d' % sys.version_info[:2]),
162 ('lib', 'python%d.%d' % sys.version_info[:2], 'site-packages'),
163 )
164
165 def create_contents(self, paths, filename):
166 """
167 Create some files in the environment which are unrelated
168 to the virtual environment.
169 """
170 for subdirs in paths:
171 d = os.path.join(self.env_dir, *subdirs)
172 os.mkdir(d)
173 fn = os.path.join(d, filename)
174 with open(fn, 'wb') as f:
175 f.write(b'Still here?')
176
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100177 def test_overwrite_existing(self):
178 """
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100179 Test creating environment in an existing directory.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100180 """
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100181 self.create_contents(self.ENV_SUBDIRS, 'foo')
182 venv.create(self.env_dir)
183 for subdirs in self.ENV_SUBDIRS:
184 fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
185 self.assertTrue(os.path.exists(fn))
186 with open(fn, 'rb') as f:
187 self.assertEqual(f.read(), b'Still here?')
188
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100189 builder = venv.EnvBuilder(clear=True)
190 builder.create(self.env_dir)
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100191 for subdirs in self.ENV_SUBDIRS:
192 fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
193 self.assertFalse(os.path.exists(fn))
194
195 def clear_directory(self, path):
196 for fn in os.listdir(path):
197 fn = os.path.join(path, fn)
198 if os.path.islink(fn) or os.path.isfile(fn):
199 os.remove(fn)
200 elif os.path.isdir(fn):
Victor Stinner866c4e22014-10-10 14:23:00 +0200201 rmtree(fn)
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100202
203 def test_unoverwritable_fails(self):
204 #create a file clashing with directories in the env dir
205 for paths in self.ENV_SUBDIRS[:3]:
206 fn = os.path.join(self.env_dir, *paths)
207 with open(fn, 'wb') as f:
208 f.write(b'')
209 self.assertRaises((ValueError, OSError), venv.create, self.env_dir)
210 self.clear_directory(self.env_dir)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100211
Vinay Sajipb3b49cd2012-05-27 18:39:22 +0100212 def test_upgrade(self):
213 """
214 Test upgrading an existing environment directory.
215 """
Vinay Sajipb9b965f2014-06-03 16:47:51 +0100216 # See Issue #21643: the loop needs to run twice to ensure
217 # that everything works on the upgrade (the first run just creates
218 # the venv).
219 for upgrade in (False, True):
220 builder = venv.EnvBuilder(upgrade=upgrade)
221 self.run_with_capture(builder.create, self.env_dir)
222 self.isdir(self.bindir)
223 self.isdir(self.include)
224 self.isdir(*self.lib)
225 fn = self.get_env_file(self.bindir, self.exe)
226 if not os.path.exists(fn):
227 # diagnostics for Windows buildbot failures
228 bd = self.get_env_file(self.bindir)
229 print('Contents of %r:' % bd)
230 print(' %r' % os.listdir(bd))
231 self.assertTrue(os.path.exists(fn), 'File %r should exist.' % fn)
Vinay Sajipb3b49cd2012-05-27 18:39:22 +0100232
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100233 def test_isolation(self):
234 """
235 Test isolation from system site-packages
236 """
237 for ssp, s in ((True, 'true'), (False, 'false')):
238 builder = venv.EnvBuilder(clear=True, system_site_packages=ssp)
239 builder.create(self.env_dir)
240 data = self.get_text_file_contents('pyvenv.cfg')
241 self.assertIn('include-system-site-packages = %s\n' % s, data)
242
243 @unittest.skipUnless(can_symlink(), 'Needs symlinks')
244 def test_symlinking(self):
245 """
246 Test symlinking works as expected
247 """
248 for usl in (False, True):
249 builder = venv.EnvBuilder(clear=True, symlinks=usl)
Vinay Sajip90db6612012-07-17 17:33:46 +0100250 builder.create(self.env_dir)
251 fn = self.get_env_file(self.bindir, self.exe)
252 # Don't test when False, because e.g. 'python' is always
253 # symlinked to 'python3.3' in the env, even when symlinking in
254 # general isn't wanted.
255 if usl:
256 self.assertTrue(os.path.islink(fn))
257
258 # If a venv is created from a source build and that venv is used to
259 # run the test, the pyvenv.cfg in the venv created in the test will
260 # point to the venv being used to run the test, and we lose the link
261 # to the source build - so Python can't initialise properly.
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000262 @skipInVenv
Vinay Sajip90db6612012-07-17 17:33:46 +0100263 def test_executable(self):
264 """
265 Test that the sys.executable value is as expected.
266 """
Victor Stinner866c4e22014-10-10 14:23:00 +0200267 rmtree(self.env_dir)
Vinay Sajip90db6612012-07-17 17:33:46 +0100268 self.run_with_capture(venv.create, self.env_dir)
269 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
270 cmd = [envpy, '-c', 'import sys; print(sys.executable)']
271 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
272 stderr=subprocess.PIPE)
273 out, err = p.communicate()
Antoine Pitrou9c92a692012-08-05 00:33:10 +0200274 self.assertEqual(out.strip(), envpy.encode())
Vinay Sajip90db6612012-07-17 17:33:46 +0100275
276 @unittest.skipUnless(can_symlink(), 'Needs symlinks')
277 def test_executable_symlinks(self):
278 """
279 Test that the sys.executable value is as expected.
280 """
Victor Stinner866c4e22014-10-10 14:23:00 +0200281 rmtree(self.env_dir)
Vinay Sajip90db6612012-07-17 17:33:46 +0100282 builder = venv.EnvBuilder(clear=True, symlinks=True)
283 builder.create(self.env_dir)
284 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
285 cmd = [envpy, '-c', 'import sys; print(sys.executable)']
286 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
287 stderr=subprocess.PIPE)
288 out, err = p.communicate()
Antoine Pitrou9c92a692012-08-05 00:33:10 +0200289 self.assertEqual(out.strip(), envpy.encode())
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100290
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000291
292@skipInVenv
293class EnsurePipTest(BaseTest):
294 """Test venv module installation of pip."""
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000295 def assert_pip_not_installed(self):
296 envpy = os.path.join(os.path.realpath(self.env_dir),
297 self.bindir, self.exe)
298 try_import = 'try:\n import pip\nexcept ImportError:\n print("OK")'
299 cmd = [envpy, '-c', try_import]
300 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
301 stderr=subprocess.PIPE)
302 out, err = p.communicate()
303 # We force everything to text, so unittest gives the detailed diff
304 # if we get unexpected results
305 err = err.decode("latin-1") # Force to text, prevent decoding errors
306 self.assertEqual(err, "")
307 out = out.decode("latin-1") # Force to text, prevent decoding errors
308 self.assertEqual(out.strip(), "OK")
309
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000310
311 def test_no_pip_by_default(self):
Victor Stinner866c4e22014-10-10 14:23:00 +0200312 rmtree(self.env_dir)
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000313 self.run_with_capture(venv.create, self.env_dir)
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000314 self.assert_pip_not_installed()
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000315
316 def test_explicit_no_pip(self):
Victor Stinner866c4e22014-10-10 14:23:00 +0200317 rmtree(self.env_dir)
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000318 self.run_with_capture(venv.create, self.env_dir, with_pip=False)
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000319 self.assert_pip_not_installed()
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000320
Nick Coghlan11c5afd2014-02-07 23:46:38 +1000321 @failsOnWindows
Nick Coghlan456ab5d2014-02-05 23:54:55 +1000322 def test_devnull_exists_and_is_empty(self):
323 # Fix for issue #20053 uses os.devnull to force a config file to
Nick Coghlan11c5afd2014-02-07 23:46:38 +1000324 # appear empty. However http://bugs.python.org/issue20541 means
325 # that doesn't currently work properly on Windows. Once that is
326 # fixed, the "win_location" part of test_with_pip should be restored
Nick Coghland49fa5e2014-02-07 22:28:18 +1000327 self.assertTrue(os.path.exists(os.devnull))
Nick Coghlan456ab5d2014-02-05 23:54:55 +1000328 with open(os.devnull, "rb") as f:
329 self.assertEqual(f.read(), b"")
330
Nick Coghlanae2ee962013-12-23 23:07:07 +1000331 # Requesting pip fails without SSL (http://bugs.python.org/issue19744)
332 @unittest.skipIf(ssl is None, ensurepip._MISSING_SSL_MESSAGE)
Berker Peksag1b25eff2016-01-19 02:01:53 +0200333 @unittest.skipUnless(threading, 'some dependencies of pip import threading'
334 ' module unconditionally')
Berker Peksag5a5ae742016-09-18 14:52:25 +0300335 # Issue #26610: pip/pep425tags.py requires ctypes
336 @unittest.skipUnless(ctypes, 'pip requires ctypes')
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000337 def test_with_pip(self):
Victor Stinner866c4e22014-10-10 14:23:00 +0200338 rmtree(self.env_dir)
Nick Coghland76cdc12013-11-23 11:37:28 +1000339 with EnvironmentVarGuard() as envvars:
340 # pip's cross-version compatibility may trigger deprecation
341 # warnings in current versions of Python. Ensure related
342 # environment settings don't cause venv to fail.
343 envvars["PYTHONWARNINGS"] = "e"
Nick Coghlan6256fcb2013-12-23 16:16:07 +1000344 # ensurepip is different enough from a normal pip invocation
345 # that we want to ensure it ignores the normal pip environment
346 # variable settings. We set PIP_NO_INSTALL here specifically
347 # to check that ensurepip (and hence venv) ignores it.
Nick Coghlan6edd82a2014-02-04 23:02:36 +1000348 # See http://bugs.python.org/issue19734
Nick Coghlan6256fcb2013-12-23 16:16:07 +1000349 envvars["PIP_NO_INSTALL"] = "1"
Nick Coghlan6edd82a2014-02-04 23:02:36 +1000350 # Also check that we ignore the pip configuration file
351 # See http://bugs.python.org/issue20053
352 with tempfile.TemporaryDirectory() as home_dir:
353 envvars["HOME"] = home_dir
354 bad_config = "[global]\nno-install=1"
355 # Write to both config file names on all platforms to reduce
356 # cross-platform variation in test code behaviour
357 win_location = ("pip", "pip.ini")
358 posix_location = (".pip", "pip.conf")
Nick Coghlan11c5afd2014-02-07 23:46:38 +1000359 # Skips win_location due to http://bugs.python.org/issue20541
360 for dirname, fname in (posix_location,):
Nick Coghlan6edd82a2014-02-04 23:02:36 +1000361 dirpath = os.path.join(home_dir, dirname)
362 os.mkdir(dirpath)
363 fpath = os.path.join(dirpath, fname)
364 with open(fpath, 'w') as f:
365 f.write(bad_config)
366
367 # Actually run the create command with all that unhelpful
368 # config in place to ensure we ignore it
369 try:
370 self.run_with_capture(venv.create, self.env_dir,
371 with_pip=True)
372 except subprocess.CalledProcessError as exc:
373 # The output this produces can be a little hard to read,
374 # but at least it has all the details
375 details = exc.output.decode(errors="replace")
376 msg = "{}\n\n**Subprocess Output**\n{}"
377 self.fail(msg.format(exc, details))
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000378 # Ensure pip is available in the virtual environment
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000379 envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
Nick Coghlan1d1d8342013-11-24 16:49:20 +1000380 cmd = [envpy, '-Im', 'pip', '--version']
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000381 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
Nick Coghlan1d1d8342013-11-24 16:49:20 +1000382 stderr=subprocess.PIPE)
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000383 out, err = p.communicate()
Nick Coghlan6fd12f22013-11-24 11:36:31 +1000384 # We force everything to text, so unittest gives the detailed diff
385 # if we get unexpected results
386 err = err.decode("latin-1") # Force to text, prevent decoding errors
387 self.assertEqual(err, "")
388 out = out.decode("latin-1") # Force to text, prevent decoding errors
Nick Coghlan1b1b1782013-11-30 15:56:58 +1000389 expected_version = "pip {}".format(ensurepip.version())
390 self.assertEqual(out[:len(expected_version)], expected_version)
Nick Coghlan6fd12f22013-11-24 11:36:31 +1000391 env_dir = os.fsencode(self.env_dir).decode("latin-1")
Nick Coghlan6fd12f22013-11-24 11:36:31 +1000392 self.assertIn(env_dir, out)
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000393
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000394 # http://bugs.python.org/issue19728
395 # Check the private uninstall command provided for the Windows
396 # installers works (at least in a virtual environment)
397 cmd = [envpy, '-Im', 'ensurepip._uninstall']
398 with EnvironmentVarGuard() as envvars:
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000399 p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
400 stderr=subprocess.PIPE)
401 out, err = p.communicate()
402 # We force everything to text, so unittest gives the detailed diff
403 # if we get unexpected results
404 err = err.decode("latin-1") # Force to text, prevent decoding errors
Victor Stinner87d6e132016-03-14 18:21:58 +0100405 # Ignore the warning:
406 # "The directory '$HOME/.cache/pip/http' or its parent directory
407 # is not owned by the current user and the cache has been disabled.
408 # Please check the permissions and owner of that directory. If
409 # executing pip with sudo, you may want sudo's -H flag."
410 # where $HOME is replaced by the HOME environment variable.
411 err = re.sub("^The directory .* or its parent directory is not owned "
412 "by the current user .*$", "", err, flags=re.MULTILINE)
413 self.assertEqual(err.rstrip(), "")
Nick Coghlan8ddd59e2013-11-30 18:35:32 +1000414 # Being fairly specific regarding the expected behaviour for the
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000415 # initial bundling phase in Python 3.4. If the output changes in
Nick Coghlan8ddd59e2013-11-30 18:35:32 +1000416 # future pip versions, this test can likely be relaxed further.
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000417 out = out.decode("latin-1") # Force to text, prevent decoding errors
Nick Coghlan8ddd59e2013-11-30 18:35:32 +1000418 self.assertIn("Successfully uninstalled pip", out)
419 self.assertIn("Successfully uninstalled setuptools", out)
420 # Check pip is now gone from the virtual environment
Nick Coghlanfdf3a622013-11-30 17:15:09 +1000421 self.assert_pip_not_installed()
422
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000423
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100424if __name__ == "__main__":
Zachary Ware38c707e2015-04-13 15:00:43 -0500425 unittest.main()