[3.13] gh-131277: allow EnvironmentVarGuard to unset more than one environment variable at once (GH-131280) (#131409)

(cherry picked from commit 3185e3115c)

---------

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
Bénédikt Tran 2025-03-18 13:48:59 +01:00 committed by GitHub
parent 25ae2045a8
commit 85c20374c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 27 additions and 36 deletions

View file

@ -1391,7 +1391,7 @@ def test_expanduser_posix(self):
p7 = P(f'~{fakename}/Documents')
with os_helper.EnvironmentVarGuard() as env:
env.pop('HOME', None)
env.unset('HOME')
self.assertEqual(p1.expanduser(), P(userhome) / 'Documents')
self.assertEqual(p2.expanduser(), P(userhome) / 'Documents')
@ -1504,10 +1504,7 @@ def test_absolute_windows(self):
def test_expanduser_windows(self):
P = self.cls
with os_helper.EnvironmentVarGuard() as env:
env.pop('HOME', None)
env.pop('USERPROFILE', None)
env.pop('HOMEPATH', None)
env.pop('HOMEDRIVE', None)
env.unset('HOME', 'USERPROFILE', 'HOMEPATH', 'HOMEDRIVE')
env['USERNAME'] = 'alice'
# test that the path returns unchanged
@ -1545,8 +1542,7 @@ def check():
env['HOMEPATH'] = 'Users\\alice'
check()
env.pop('HOMEDRIVE', None)
env.pop('HOMEPATH', None)
env.unset('HOMEDRIVE', 'HOMEPATH')
env['USERPROFILE'] = 'C:\\Users\\alice'
check()