]> granicus.if.org Git - python/commitdiff
Issue #21493: Added test for ntpath.expanduser(). Original patch by
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 28 May 2014 15:11:29 +0000 (18:11 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 28 May 2014 15:11:29 +0000 (18:11 +0300)
Claudiu Popa.

Lib/test/test_ntpath.py
Misc/NEWS

index 000fc75c205dd0ae58ce2760be7850a5bd09c3eb..376f7ed141093b7bf6c0d91a1d4ef9dc18371de1 100644 (file)
@@ -258,6 +258,41 @@ class TestNtpath(unittest.TestCase):
             check('%spam%bar', '%sbar' % nonascii)
             check('%{}%bar'.format(nonascii), 'ham%sbar' % nonascii)
 
+    def test_expanduser(self):
+        tester('ntpath.expanduser("test")', 'test')
+
+        with support.EnvironmentVarGuard() as env:
+            env.clear()
+            tester('ntpath.expanduser("~test")', '~test')
+
+            env['HOMEPATH'] = 'eric\\idle'
+            env['HOMEDRIVE'] = 'C:\\'
+            tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
+            tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
+
+            del env['HOMEDRIVE']
+            tester('ntpath.expanduser("~test")', 'eric\\test')
+            tester('ntpath.expanduser("~")', 'eric\\idle')
+
+            env.clear()
+            env['USERPROFILE'] = 'C:\\eric\\idle'
+            tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
+            tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
+
+            env.clear()
+            env['HOME'] = 'C:\\idle\\eric'
+            tester('ntpath.expanduser("~test")', 'C:\\idle\\test')
+            tester('ntpath.expanduser("~")', 'C:\\idle\\eric')
+
+            tester('ntpath.expanduser("~test\\foo\\bar")',
+                   'C:\\idle\\test\\foo\\bar')
+            tester('ntpath.expanduser("~test/foo/bar")',
+                   'C:\\idle\\test/foo/bar')
+            tester('ntpath.expanduser("~\\foo\\bar")',
+                   'C:\\idle\\eric\\foo\\bar')
+            tester('ntpath.expanduser("~/foo/bar")',
+                   'C:\\idle\\eric/foo/bar')
+
     def test_abspath(self):
         # ntpath.abspath() can only be used on a system with the "nt" module
         # (reasonably), so we protect this test with "import nt".  This allows
index 57cf50fe9b436c1837700702fc85ecf37e36e63e..f82d3c565c5d7a799c2629774c7b42c14eeaad99 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@ Library
 Tests
 -----
 
+- Issue #21493: Added test for ntpath.expanduser().  Original patch by
+  Claudiu Popa.
+
 - Issue #19925: Added tests for the spwd module. Original patch by Vajrasky Kok.
 
 - Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),