[3.12] gh-121200: Fix test_expanduser_pwd2() of test_posixpath (GH-121228) (#121231)

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 02cb5fdee3)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2024-07-01 18:05:30 +02:00 committed by GitHub
parent e2a97d1db0
commit dec9d916d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View 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))

View file

@ -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.