Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ffc1e6d

Browse files
Issue #21493: Added test for ntpath.expanduser(). Original patch by
Claudiu Popa.
1 parent 47a9813 commit ffc1e6d

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lib/test/test_ntpath.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,41 @@ def check(value, expected):
258258
check('%spam%bar', '%sbar' % nonascii)
259259
check('%{}%bar'.format(nonascii), 'ham%sbar' % nonascii)
260260

261+
def test_expanduser(self):
262+
tester('ntpath.expanduser("test")', 'test')
263+
264+
with support.EnvironmentVarGuard() as env:
265+
env.clear()
266+
tester('ntpath.expanduser("~test")', '~test')
267+
268+
env['HOMEPATH'] = 'eric\\idle'
269+
env['HOMEDRIVE'] = 'C:\\'
270+
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
271+
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
272+
273+
del env['HOMEDRIVE']
274+
tester('ntpath.expanduser("~test")', 'eric\\test')
275+
tester('ntpath.expanduser("~")', 'eric\\idle')
276+
277+
env.clear()
278+
env['USERPROFILE'] = 'C:\\eric\\idle'
279+
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
280+
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
281+
282+
env.clear()
283+
env['HOME'] = 'C:\\idle\\eric'
284+
tester('ntpath.expanduser("~test")', 'C:\\idle\\test')
285+
tester('ntpath.expanduser("~")', 'C:\\idle\\eric')
286+
287+
tester('ntpath.expanduser("~test\\foo\\bar")',
288+
'C:\\idle\\test\\foo\\bar')
289+
tester('ntpath.expanduser("~test/foo/bar")',
290+
'C:\\idle\\test/foo/bar')
291+
tester('ntpath.expanduser("~\\foo\\bar")',
292+
'C:\\idle\\eric\\foo\\bar')
293+
tester('ntpath.expanduser("~/foo/bar")',
294+
'C:\\idle\\eric/foo/bar')
295+
261296
def test_abspath(self):
262297
# ntpath.abspath() can only be used on a system with the "nt" module
263298
# (reasonably), so we protect this test with "import nt". This allows

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Library
4646
Tests
4747
-----
4848

49+
- Issue #21493: Added test for ntpath.expanduser(). Original patch by
50+
Claudiu Popa.
51+
4952
- Issue #19925: Added tests for the spwd module. Original patch by Vajrasky Kok.
5053

5154
- Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),

0 commit comments

Comments
 (0)