Skip to content

Commit 7f935f4

Browse files
committed
use boosted unset() in some test files
1 parent 09c4aae commit 7f935f4

File tree

12 files changed

+23
-39
lines changed

12 files changed

+23
-39
lines changed

Lib/test/support/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,8 +2855,7 @@ def no_color():
28552855
swap_attr(_colorize, "can_colorize", lambda file=None: False),
28562856
EnvironmentVarGuard() as env,
28572857
):
2858-
for var in {"FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS"}:
2859-
env.unset(var)
2858+
env.unset("FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS")
28602859
env.set("NO_COLOR", "1")
28612860
yield
28622861

Lib/test/test__colorize.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
@contextlib.contextmanager
1111
def clear_env():
1212
with EnvironmentVarGuard() as mock_env:
13-
for var in "FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS", "TERM":
14-
mock_env.unset(var)
13+
mock_env.unset("FORCE_COLOR", "NO_COLOR", "PYTHON_COLORS", "TERM")
1514
yield mock_env
1615

1716

Lib/test/test__osx_support.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ def setUp(self):
2020
self.prog_name = 'bogus_program_xxxx'
2121
self.temp_path_dir = os.path.abspath(os.getcwd())
2222
self.env = self.enterContext(os_helper.EnvironmentVarGuard())
23-
for cv in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS',
24-
'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',
25-
'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
26-
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS'):
27-
if cv in self.env:
28-
self.env.unset(cv)
23+
24+
self.env.unset(
25+
'CFLAGS', 'LDFLAGS', 'CPPFLAGS',
26+
'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',
27+
'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
28+
'PY_CORE_CFLAGS', 'PY_CORE_LDFLAGS'
29+
)
2930

3031
def add_expected_saved_initial_values(self, config_vars, expected_vars):
3132
# Ensure that the initial values for all modified config vars

Lib/test/test_builtin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,8 +1568,7 @@ def test_open_default_encoding(self):
15681568
# try to get a user preferred encoding different than the current
15691569
# locale encoding to check that open() uses the current locale
15701570
# encoding and not the user preferred encoding
1571-
for key in ('LC_ALL', 'LANG', 'LC_CTYPE'):
1572-
env.unset(key)
1571+
env.unset('LC_ALL', 'LANG', 'LC_CTYPE')
15731572

15741573
self.write_testfile()
15751574
current_locale_encoding = locale.getencoding()

Lib/test/test_getopt.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
class GetoptTests(unittest.TestCase):
1414
def setUp(self):
1515
self.env = self.enterContext(EnvironmentVarGuard())
16-
if "POSIXLY_CORRECT" in self.env:
17-
del self.env["POSIXLY_CORRECT"]
16+
del self.env["POSIXLY_CORRECT"]
1817

1918
def assertError(self, *args, **kwargs):
2019
self.assertRaises(getopt.GetoptError, *args, **kwargs)

Lib/test/test_io.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,8 +2896,7 @@ def test_default_encoding(self):
28962896
# try to get a user preferred encoding different than the current
28972897
# locale encoding to check that TextIOWrapper() uses the current
28982898
# locale encoding and not the user preferred encoding
2899-
for key in ('LC_ALL', 'LANG', 'LC_CTYPE'):
2900-
env.unset(key)
2899+
env.unset('LC_ALL', 'LANG', 'LC_CTYPE')
29012900

29022901
current_locale_encoding = locale.getencoding()
29032902
b = self.BytesIO()

Lib/test/test_locale.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,7 @@ def test_defaults_UTF8(self):
500500

501501
try:
502502
with os_helper.EnvironmentVarGuard() as env:
503-
for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'):
504-
env.unset(key)
505-
503+
env.unset('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')
506504
env.set('LC_CTYPE', 'UTF-8')
507505

508506
with check_warnings(('', DeprecationWarning)):

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ def test_expanduser_posix(self):
32323232
p7 = P(f'~{fakename}/Documents')
32333233

32343234
with os_helper.EnvironmentVarGuard() as env:
3235-
env.pop('HOME', None)
3235+
env.unset('HOME')
32363236

32373237
self.assertEqual(p1.expanduser(), P(userhome) / 'Documents')
32383238
self.assertEqual(p2.expanduser(), P(userhome) / 'Documents')
@@ -3345,10 +3345,7 @@ def test_absolute_windows(self):
33453345
def test_expanduser_windows(self):
33463346
P = self.cls
33473347
with os_helper.EnvironmentVarGuard() as env:
3348-
env.pop('HOME', None)
3349-
env.pop('USERPROFILE', None)
3350-
env.pop('HOMEPATH', None)
3351-
env.pop('HOMEDRIVE', None)
3348+
env.unset('HOME', 'USERPROFILE', 'HOMEPATH', 'HOMEDRIVE')
33523349
env['USERNAME'] = 'alice'
33533350

33543351
# test that the path returns unchanged
@@ -3386,8 +3383,7 @@ def check():
33863383
env['HOMEPATH'] = 'Users\\alice'
33873384
check()
33883385

3389-
env.pop('HOMEDRIVE', None)
3390-
env.pop('HOMEPATH', None)
3386+
env.unset('HOMEDRIVE', 'HOMEPATH')
33913387
env['USERPROFILE'] = 'C:\\Users\\alice'
33923388
check()
33933389

Lib/test/test_platform.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ def raises_oserror(*a):
368368
with support.swap_attr(platform, '_wmi_query', raises_oserror):
369369
with os_helper.EnvironmentVarGuard() as environ:
370370
try:
371-
if 'PROCESSOR_ARCHITEW6432' in environ:
372-
del environ['PROCESSOR_ARCHITEW6432']
371+
del environ['PROCESSOR_ARCHITEW6432']
373372
environ['PROCESSOR_ARCHITECTURE'] = 'foo'
374373
platform._uname_cache = None
375374
system, node, release, version, machine, processor = platform.uname()

Lib/test/test_regrtest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ def create_regrtest(self, args):
422422
# which has an unclear API
423423
with os_helper.EnvironmentVarGuard() as env:
424424
# Ignore SOURCE_DATE_EPOCH env var if it's set
425-
if 'SOURCE_DATE_EPOCH' in env:
426-
del env['SOURCE_DATE_EPOCH']
425+
del env['SOURCE_DATE_EPOCH']
427426

428427
regrtest = main.Regrtest(ns)
429428

0 commit comments

Comments
 (0)