mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Closes #15776: pyvenv now works with existing directories.
This commit is contained in:
parent
24dfdb69ca
commit
bd40d3e144
3 changed files with 74 additions and 13 deletions
|
@ -113,13 +113,68 @@ class BasicTest(BaseTest):
|
|||
out, err = p.communicate()
|
||||
self.assertEqual(out.strip(), expected.encode())
|
||||
|
||||
if sys.platform == 'win32':
|
||||
ENV_SUBDIRS = (
|
||||
('Scripts',),
|
||||
('Include',),
|
||||
('Lib',),
|
||||
('Lib', 'site-packages'),
|
||||
)
|
||||
else:
|
||||
ENV_SUBDIRS = (
|
||||
('bin',),
|
||||
('include',),
|
||||
('lib',),
|
||||
('lib', 'python%d.%d' % sys.version_info[:2]),
|
||||
('lib', 'python%d.%d' % sys.version_info[:2], 'site-packages'),
|
||||
)
|
||||
|
||||
def create_contents(self, paths, filename):
|
||||
"""
|
||||
Create some files in the environment which are unrelated
|
||||
to the virtual environment.
|
||||
"""
|
||||
for subdirs in paths:
|
||||
d = os.path.join(self.env_dir, *subdirs)
|
||||
os.mkdir(d)
|
||||
fn = os.path.join(d, filename)
|
||||
with open(fn, 'wb') as f:
|
||||
f.write(b'Still here?')
|
||||
|
||||
def test_overwrite_existing(self):
|
||||
"""
|
||||
Test control of overwriting an existing environment directory.
|
||||
Test creating environment in an existing directory.
|
||||
"""
|
||||
self.assertRaises(ValueError, venv.create, self.env_dir)
|
||||
self.create_contents(self.ENV_SUBDIRS, 'foo')
|
||||
venv.create(self.env_dir)
|
||||
for subdirs in self.ENV_SUBDIRS:
|
||||
fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
|
||||
self.assertTrue(os.path.exists(fn))
|
||||
with open(fn, 'rb') as f:
|
||||
self.assertEqual(f.read(), b'Still here?')
|
||||
|
||||
builder = venv.EnvBuilder(clear=True)
|
||||
builder.create(self.env_dir)
|
||||
for subdirs in self.ENV_SUBDIRS:
|
||||
fn = os.path.join(self.env_dir, *(subdirs + ('foo',)))
|
||||
self.assertFalse(os.path.exists(fn))
|
||||
|
||||
def clear_directory(self, path):
|
||||
for fn in os.listdir(path):
|
||||
fn = os.path.join(path, fn)
|
||||
if os.path.islink(fn) or os.path.isfile(fn):
|
||||
os.remove(fn)
|
||||
elif os.path.isdir(fn):
|
||||
shutil.rmtree(fn)
|
||||
|
||||
def test_unoverwritable_fails(self):
|
||||
#create a file clashing with directories in the env dir
|
||||
for paths in self.ENV_SUBDIRS[:3]:
|
||||
fn = os.path.join(self.env_dir, *paths)
|
||||
with open(fn, 'wb') as f:
|
||||
f.write(b'')
|
||||
self.assertRaises((ValueError, OSError), venv.create, self.env_dir)
|
||||
self.clear_directory(self.env_dir)
|
||||
|
||||
def test_upgrade(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue