summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-01-28 01:59:43 -0800
committerGitHub <noreply@github.com>2020-01-28 01:59:43 -0800
commit595b516965ee88b817dc1b3d7713e1f3f263634d (patch)
treefd9f482a0fd5a39057bec69349325c089520b43c /Lib
parent41f4dc3bcf30cb8362a062a26818311c704ea89f (diff)
downloadcpython-git-595b516965ee88b817dc1b3d7713e1f3f263634d.tar.gz
bpo-38883: Don't use POSIX `$HOME` in `pathlib.Path.home/expanduser` on Windows (GH-17961)
In bpo-36264 os.path.expanduser was changed to ignore HOME on Windows. Path.expanduser/home still honored HOME despite being documented as behaving the same as os.path.expanduser. This makes them also ignore HOME so that both implementations behave the same way again. (cherry picked from commit c45a2aa9e255b5c7c211faa79f6b23895b64ab27) Co-authored-by: Christoph Reiter <reiter.christoph@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/pathlib.py4
-rw-r--r--Lib/test/test_pathlib.py22
2 files changed, 15 insertions, 11 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 8ed3c883c6..015370a860 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -253,9 +253,7 @@ class _WindowsFlavour(_Flavour):
return 'file:' + urlquote_from_bytes(path.as_posix().encode('utf-8'))
def gethomedir(self, username):
- if 'HOME' in os.environ:
- userhome = os.environ['HOME']
- elif 'USERPROFILE' in os.environ:
+ if 'USERPROFILE' in os.environ:
userhome = os.environ['USERPROFILE']
elif 'HOMEPATH' in os.environ:
try:
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index b127343982..97fc5d8ad7 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1296,8 +1296,16 @@ class _BasePathTest(object):
self.assertTrue(p.is_absolute())
def test_home(self):
- p = self.cls.home()
- self._test_home(p)
+ with support.EnvironmentVarGuard() as env:
+ self._test_home(self.cls.home())
+
+ env.clear()
+ env['USERPROFILE'] = os.path.join(BASE, 'userprofile')
+ self._test_home(self.cls.home())
+
+ # bpo-38883: ignore `HOME` when set on windows
+ env['HOME'] = os.path.join(BASE, 'home')
+ self._test_home(self.cls.home())
def test_samefile(self):
fileA_path = os.path.join(BASE, 'fileA')
@@ -2348,12 +2356,6 @@ class WindowsPathTest(_BasePathTest, unittest.TestCase):
self.assertEqual(p5.expanduser(), p5)
self.assertEqual(p6.expanduser(), p6)
- # Test the first lookup key in the env vars.
- env['HOME'] = 'C:\\Users\\alice'
- check()
-
- # Test that HOMEPATH is available instead.
- env.pop('HOME', None)
env['HOMEPATH'] = 'C:\\Users\\alice'
check()
@@ -2366,6 +2368,10 @@ class WindowsPathTest(_BasePathTest, unittest.TestCase):
env['USERPROFILE'] = 'C:\\Users\\alice'
check()
+ # bpo-38883: ignore `HOME` when set on windows
+ env['HOME'] = 'C:\\Users\\eve'
+ check()
+
class CompatiblePathTest(unittest.TestCase):
"""