summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacek <jacek.duszenko@gmail.com>2024-09-18 22:05:18 (GMT)
committerGitHub <noreply@github.com>2024-09-18 22:05:18 (GMT)
commitea7fe1fe2e162f2375562467ad834c6224a62daf (patch)
tree66eb327094f2f74cbfbfc22ffb3c753f90bbd4bb
parent36682c091407dc9c7e750c22fb71e62466952662 (diff)
downloadcpython-ea7fe1fe2e162f2375562467ad834c6224a62daf.zip
cpython-ea7fe1fe2e162f2375562467ad834c6224a62daf.tar.gz
cpython-ea7fe1fe2e162f2375562467ad834c6224a62daf.tar.bz2
gh-124212: Fix undefined variable in error message in venv (GH-124211)
-rw-r--r--Lib/test/test_venv.py15
-rw-r--r--Lib/venv/__init__.py2
-rw-r--r--Misc/NEWS.d/next/Library/2024-09-18-17-45-52.gh-issue-124212.n6kIby.rst1
3 files changed, 17 insertions, 1 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index b9fcc59..1ef08da 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -504,6 +504,21 @@ class BasicTest(BaseTest):
)
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
def test_multiprocessing(self):
"""
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index fa69d58..028e948 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -393,7 +393,7 @@ class EnvBuilder:
os.symlink(src, dest)
to_unlink.append(dest)
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
for f in to_unlink:
try:
diff --git a/Misc/NEWS.d/next/Library/2024-09-18-17-45-52.gh-issue-124212.n6kIby.rst b/Misc/NEWS.d/next/Library/2024-09-18-17-45-52.gh-issue-124212.n6kIby.rst
new file mode 100644
index 0000000..7848f26
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-09-18-17-45-52.gh-issue-124212.n6kIby.rst
@@ -0,0 +1 @@
+Fix invalid variable in :mod:`venv` handling of failed symlink on Windows