@@ -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
0 commit comments