diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-03 18:17:52 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-05-03 18:17:52 (GMT) |
commit | 0e120525f0a2dfcd417905593cad27169907a4d5 (patch) | |
tree | 70b1e22f6217249335602dc1650d834b1fb172be | |
parent | 478be14ec0a2ae44e6ab78ed79ea8d238581a4d2 (diff) | |
parent | a3fd0b26ba7d302475e051b698c86f512d0e7a14 (diff) | |
download | cpython-0e120525f0a2dfcd417905593cad27169907a4d5.zip cpython-0e120525f0a2dfcd417905593cad27169907a4d5.tar.gz cpython-0e120525f0a2dfcd417905593cad27169907a4d5.tar.bz2 |
Issue #24950: Fixed expanduser tests when the users home directory in pwd is "/".
Based on patch by SilentGhost.
-rw-r--r-- | Lib/test/test_pathlib.py | 2 | ||||
-rw-r--r-- | Lib/test/test_posixpath.py | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index b32c9fb..6119bc1 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2062,7 +2062,7 @@ class PosixPathTest(_BasePathTest, unittest.TestCase): import pwd pwdent = pwd.getpwuid(os.getuid()) username = pwdent.pw_name - userhome = pwdent.pw_dir.rstrip('/') + userhome = pwdent.pw_dir.rstrip('/') or '/' # find arbitrary different user (if exists) for pwdent in pwd.getpwall(): othername = pwdent.pw_name diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index 26faa48..4ff445d 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -214,6 +214,13 @@ class PosixPathTest(unittest.TestCase): def test_expanduser(self): self.assertEqual(posixpath.expanduser("foo"), "foo") self.assertEqual(posixpath.expanduser(b"foo"), b"foo") + with support.EnvironmentVarGuard() as env: + for home in '/', '', '//', '///': + with self.subTest(home=home): + env['HOME'] = home + self.assertEqual(posixpath.expanduser("~"), "/") + self.assertEqual(posixpath.expanduser("~/"), "/") + self.assertEqual(posixpath.expanduser("~/foo"), "/foo") try: import pwd except ImportError: @@ -237,14 +244,12 @@ class PosixPathTest(unittest.TestCase): self.assertIsInstance(posixpath.expanduser(b"~foo/"), bytes) with 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) - self.assertEqual(posixpath.expanduser("~"), home.rstrip("/")) + home = home.rstrip("/") or '/' + self.assertEqual(posixpath.expanduser("~"), home) def test_normpath(self): self.assertEqual(posixpath.normpath(""), ".") |