]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-124212: Fix undefined variable in error message in venv (GH-124211)
authorJacek <jacek.duszenko@gmail.com>
Wed, 18 Sep 2024 22:05:18 +0000 (00:05 +0200)
committerGitHub <noreply@github.com>
Wed, 18 Sep 2024 22:05:18 +0000 (22:05 +0000)
Lib/test/test_venv.py
Lib/venv/__init__.py
Misc/NEWS.d/next/Library/2024-09-18-17-45-52.gh-issue-124212.n6kIby.rst [new file with mode: 0644]

index b9fcc59d49668c3b595b0284dd63461bb1123530..1ef08da326c18c2b7bf24c843431eaa1e7544689 100644 (file)
@@ -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):
         """
index fa69d5846f2fa795353b0268c03aa2e313dcf4c1..028e94831966941228ab7d10145f03aec72480e1 100644 (file)
@@ -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 (file)
index 0000000..7848f26
--- /dev/null
@@ -0,0 +1 @@
+Fix invalid variable in :mod:`venv` handling of failed symlink on Windows