[Python-checkins] cpython (2.7): Backported test for posixpath.expanduser().
serhiy.storchaka
python-checkins at python.org
Tue May 3 15:15:57 EDT 2016
https://hg.python.org/cpython/rev/e07e2b8c9429
changeset: 101219:e07e2b8c9429
branch: 2.7
parent: 101214:21d18f09822b
user: Serhiy Storchaka <storchaka at gmail.com>
date: Tue May 03 22:15:29 2016 +0300
summary:
Backported test for posixpath.expanduser().
files:
Lib/test/test_posixpath.py | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -198,6 +198,12 @@
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 @@
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(""), ".")
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list