mirror of
https://github.com/python/cpython.git
synced 2025-10-29 20:51:26 +00:00
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.
This commit is contained in:
parent
61f4db8c56
commit
c45a2aa9e2
3 changed files with 20 additions and 11 deletions
|
|
@ -1383,8 +1383,16 @@ def _test_home(self, p):
|
|||
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')
|
||||
|
|
@ -2448,12 +2456,6 @@ def check():
|
|||
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()
|
||||
|
||||
|
|
@ -2466,6 +2468,10 @@ def check():
|
|||
env['USERPROFILE'] = 'C:\\Users\\alice'
|
||||
check()
|
||||
|
||||
# bpo-38883: ignore `HOME` when set on windows
|
||||
env['HOME'] = 'C:\\Users\\eve'
|
||||
check()
|
||||
|
||||
|
||||
class CompatiblePathTest(unittest.TestCase):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue