[3.13] gh-124212: Fix undefined variable in error message in venv (GH-124211) (#124226)

gh-124212: Fix undefined variable in error message in venv (GH-124211)
(cherry picked from commit ea7fe1fe2e)

Co-authored-by: Jacek <jacek.duszenko@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-09-30 03:11:22 +02:00 committed by GitHub
parent 0a868db982
commit 32acfdb678
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 1 deletions

View File

@ -504,6 +504,21 @@ def test_unicode_in_batch_file(self):
) )
self.assertEqual(out.strip(), '0') self.assertEqual(out.strip(), '0')
@unittest.skipUnless(os.name == 'nt' and can_symlink(),
'symlinks on Windows')
def test_failed_symlink(self):
"""
Test handling of failed symlinks on Windows.
"""
rmtree(self.env_dir)
env_dir = os.path.join(os.path.realpath(self.env_dir), 'venv')
with patch('os.symlink') as mock_symlink:
mock_symlink.side_effect = OSError()
builder = venv.EnvBuilder(clear=True, symlinks=True)
_, err = self.run_with_capture(builder.create, env_dir)
filepath_regex = r"'[A-Z]:\\\\(?:[^\\\\]+\\\\)*[^\\\\]+'"
self.assertRegex(err, rf"Unable to symlink {filepath_regex} to {filepath_regex}")
@requireVenvCreate @requireVenvCreate
def test_multiprocessing(self): def test_multiprocessing(self):
""" """

View File

@ -393,7 +393,7 @@ def setup_python(self, context):
os.symlink(src, dest) os.symlink(src, dest)
to_unlink.append(dest) to_unlink.append(dest)
except OSError: except OSError:
logger.warning('Unable to symlink %r to %r', src, dst) logger.warning('Unable to symlink %r to %r', src, dest)
do_copies = True do_copies = True
for f in to_unlink: for f in to_unlink:
try: try:

View File

@ -0,0 +1 @@
Fix invalid variable in :mod:`venv` handling of failed symlink on Windows