Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2443,13 +2443,21 @@ def test_expanduser(self):
othername = username
otherhome = userhome

fakename = 'fakeuser'
# This user can theoretically exist on a test runner. Create unique name:
try:
while pwd.getpwnam(fakename):
fakename += '1'
except KeyError:
pass # Non-existent name found

p1 = P('~/Documents')
p2 = P('~' + username + '/Documents')
p3 = P('~' + othername + '/Documents')
p4 = P('../~' + username + '/Documents')
p5 = P('/~' + username + '/Documents')
p2 = P(f'~{username}/Documents')
p3 = P(f'~{othername}/Documents')
p4 = P(f'../~{username}/Documents')
p5 = P(f'/~{username}/Documents')
p6 = P('')
p7 = P('~fake800813user/Documents')
p7 = P(f'~{fakename}/Documents')

with support.EnvironmentVarGuard() as env:
env.pop('HOME', None)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Now ``fakename`` in ``test_pathlib.PosixPathTest.test_expanduser`` is checked
to be non-existent.