summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-05-03 19:15:29 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-05-03 19:15:29 (GMT)
commit7dc8e1e95e24bdd77bd40828abeb181fd411bec3 (patch)
treea2434af0f7e0168734f4f5f43c48c004b149eda6 /Lib
parent7d03c8463477b0e314f594bb9988e49dc0945be9 (diff)
downloadcpython-7dc8e1e95e24bdd77bd40828abeb181fd411bec3.zip
cpython-7dc8e1e95e24bdd77bd40828abeb181fd411bec3.tar.gz
cpython-7dc8e1e95e24bdd77bd40828abeb181fd411bec3.tar.bz2
Backported test for posixpath.expanduser().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_posixpath.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 686b6b9..fbb18fd 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -198,6 +198,12 @@ class PosixPathTest(unittest.TestCase):
def test_expanduser(self):
self.assertEqual(posixpath.expanduser("foo"), "foo")
+ with test_support.EnvironmentVarGuard() as env:
+ for home in '/', '', '//', '///':
+ env['HOME'] = home
+ self.assertEqual(posixpath.expanduser("~"), "/")
+ self.assertEqual(posixpath.expanduser("~/"), "/")
+ self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
try:
import pwd
except ImportError:
@@ -214,9 +220,12 @@ class PosixPathTest(unittest.TestCase):
self.assertIsInstance(posixpath.expanduser("~foo/"), basestring)
with test_support.EnvironmentVarGuard() as env:
- env['HOME'] = '/'
- self.assertEqual(posixpath.expanduser("~"), "/")
- self.assertEqual(posixpath.expanduser("~/foo"), "/foo")
+ # expanduser should fall back to using the password database
+ del env['HOME']
+ home = pwd.getpwuid(os.getuid()).pw_dir
+ # $HOME can end with a trailing /, so strip it (see #17809)
+ home = home.rstrip("/") or '/'
+ self.assertEqual(posixpath.expanduser("~"), home)
def test_normpath(self):
self.assertEqual(posixpath.normpath(""), ".")