Issue #15184: Ensure configuration-related environment variables

are unset during test execution.
This commit is contained in:
Ned Deily 2012-07-21 09:29:54 -07:00
parent 636601dfba
commit 2731c049ac

View File

@ -20,6 +20,14 @@ class Test_OSXSupport(unittest.TestCase):
self.maxDiff = None
self.prog_name = 'bogus_program_xxxx'
self.temp_path_dir = os.path.abspath(os.getcwd())
self.env = test.support.EnvironmentVarGuard()
self.addCleanup(self.env.__exit__)
for cv in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS',
'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'CC',
'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS',
'PY_CORE_CFLAGS'):
if cv in self.env:
self.env.unset(cv)
def add_expected_saved_initial_values(self, config_vars, expected_vars):
# Ensure that the initial values for all modified config vars
@ -29,10 +37,9 @@ class Test_OSXSupport(unittest.TestCase):
if config_vars[k] != expected_vars[k])
def test__find_executable(self):
with test.support.EnvironmentVarGuard() as env:
if env['PATH']:
env['PATH'] = env['PATH'] + ':'
env['PATH'] = env['PATH'] + os.path.abspath(self.temp_path_dir)
if self.env['PATH']:
self.env['PATH'] = self.env['PATH'] + ':'
self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir)
test.support.unlink(self.prog_name)
self.assertIsNone(_osx_support._find_executable(self.prog_name))
self.addCleanup(test.support.unlink, self.prog_name)
@ -43,10 +50,9 @@ class Test_OSXSupport(unittest.TestCase):
_osx_support._find_executable(self.prog_name))
def test__read_output(self):
with test.support.EnvironmentVarGuard() as env:
if env['PATH']:
env['PATH'] = env['PATH'] + ':'
env['PATH'] = env['PATH'] + os.path.abspath(self.temp_path_dir)
if self.env['PATH']:
self.env['PATH'] = self.env['PATH'] + ':'
self.env['PATH'] = self.env['PATH'] + os.path.abspath(self.temp_path_dir)
test.support.unlink(self.prog_name)
self.addCleanup(test.support.unlink, self.prog_name)
with open(self.prog_name, 'w') as f:
@ -133,9 +139,8 @@ class Test_OSXSupport(unittest.TestCase):
}
self.add_expected_saved_initial_values(config_vars, expected_vars)
with test.support.EnvironmentVarGuard() as env:
suffix = (':' + env['PATH']) if env['PATH'] else ''
env['PATH'] = os.path.abspath(self.temp_path_dir) + suffix
suffix = (':' + self.env['PATH']) if self.env['PATH'] else ''
self.env['PATH'] = os.path.abspath(self.temp_path_dir) + suffix
for c_name, c_output in compilers:
test.support.unlink(c_name)
self.addCleanup(test.support.unlink, c_name)
@ -195,8 +200,7 @@ class Test_OSXSupport(unittest.TestCase):
config_vars))
def test__override_all_archs(self):
with test.support.EnvironmentVarGuard() as env:
env['ARCHFLAGS'] = '-arch x86_64'
self.env['ARCHFLAGS'] = '-arch x86_64'
config_vars = {
'CC': 'clang',
'CFLAGS': '-fno-strict-aliasing -g -O3 -arch ppc -arch i386 ',