Skip to content

Commit

Permalink
pythongh-121200: Fix test_expanduser_pwd2() of test_posixpath (python…
Browse files Browse the repository at this point in the history
…#121228)

Call getpwnam() to get pw_dir, since it can be different than
getpwall() pw_dir.
  • Loading branch information
vstinner committed Jul 1, 2024
1 parent 8a51767 commit 02cb5fd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Lib/test/test_posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,16 @@ def test_expanduser_pwd(self):
"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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 02cb5fd

Please sign in to comment.