]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228) (#121231)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 1 Jul 2024 16:05:30 +0000 (18:05 +0200)
committerGitHub <noreply@github.com>
Mon, 1 Jul 2024 16:05:30 +0000 (16:05 +0000)
gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228)

Call getpwnam() to get pw_dir, since it can be different than
getpwall() pw_dir.
(cherry picked from commit 02cb5fdee391670d63b2fc0a92ca9b36a32ac95a)

Co-authored-by: Victor Stinner <vstinner@python.org>
Lib/test/test_posixpath.py
Misc/NEWS.d/next/Tests/2024-07-01-16-15-06.gh-issue-121200.4Pc-gc.rst [new file with mode: 0644]

index 9f54311d2ad60b5548a06cd3f4625e32eed822cc..cc4fd2f4c9512c22eea8f217c235bbbe151bc80d 100644 (file)
@@ -347,11 +347,16 @@ class PosixPathTest(unittest.TestCase):
                      "no home directory on VxWorks")
     def test_expanduser_pwd2(self):
         pwd = import_helper.import_module('pwd')
-        for entry in pwd.getpwall():
-            name = entry.pw_name
+        for all_entry in pwd.getpwall():
+            name = all_entry.pw_name
+
+            # gh-121200: pw_dir can be different between getpwall() and
+            # getpwnam(), so use getpwnam() pw_dir as expanduser() does.
+            entry = pwd.getpwnam(name)
             home = entry.pw_dir
             home = home.rstrip('/') or '/'
-            with self.subTest(pwd=entry):
+
+            with self.subTest(all_entry=all_entry, entry=entry):
                 self.assertEqual(posixpath.expanduser('~' + name), home)
                 self.assertEqual(posixpath.expanduser(os.fsencode('~' + name)),
                                  os.fsencode(home))
diff --git a/Misc/NEWS.d/next/Tests/2024-07-01-16-15-06.gh-issue-121200.4Pc-gc.rst b/Misc/NEWS.d/next/Tests/2024-07-01-16-15-06.gh-issue-121200.4Pc-gc.rst
new file mode 100644 (file)
index 0000000..01e0d9b
--- /dev/null
@@ -0,0 +1,3 @@
+Fix ``test_expanduser_pwd2()`` of ``test_posixpath``.  Call ``getpwnam()``
+to get ``pw_dir``, since it can be different than ``getpwall()`` ``pw_dir``.
+Patch by Victor Stinner.