Commit 8c380e99 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-36235: Enhance distutils test_customize_compiler() (GH-12403) (GH-12417)

The test test_customize_compiler() now mocks all sysconfig variables
and all environment variables used by customize_compiler().

(cherry picked from commit 72c7b372)
parent 37f69717
......@@ -51,14 +51,7 @@ class SysconfigTestCase(support.EnvironGuard,
python_h = os.path.join(inc_dir, "Python.h")
self.assertTrue(os.path.isfile(python_h), python_h)
@unittest.skipUnless(get_default_compiler() == 'unix',
'not testing if default compiler is not unix')
def test_customize_compiler(self):
os.environ['AR'] = 'my_ar'
os.environ['CC'] = 'my_cc'
os.environ['ARFLAGS'] = '--myarflags'
os.environ['CFLAGS'] = '--mycflags'
def customize_compiler(self):
# make sure AR gets caught
class compiler:
compiler_type = 'unix'
......@@ -66,14 +59,90 @@ class SysconfigTestCase(support.EnvironGuard,
def set_executables(self, **kw):
self.exes = kw
# Make sure that sysconfig._config_vars is initialized
sysconfig.get_config_vars()
sysconfig_vars = {
'AR': 'sc_ar',
'CC': 'sc_cc',
'CXX': 'sc_cxx',
'ARFLAGS': '--sc-arflags',
'CFLAGS': '--sc-cflags',
'CCSHARED': '--sc-ccshared',
'LDSHARED': 'sc_ldshared',
'SO': 'sc_shutil_suffix',
}
comp = compiler()
with swap_item(sysconfig._config_vars, 'CFLAGS', '--sysconfig-cflags'):
old_vars = dict(sysconfig._config_vars)
try:
for key, value in sysconfig_vars.items():
sysconfig._config_vars[key] = value
sysconfig.customize_compiler(comp)
self.assertEqual(comp.exes['archiver'], 'my_ar --myarflags')
self.assertEqual(comp.exes['compiler'], 'my_cc --sysconfig-cflags --mycflags')
finally:
sysconfig._config_vars.clear()
sysconfig._config_vars.update(old_vars)
return comp
@unittest.skipUnless(get_default_compiler() == 'unix',
'not testing if default compiler is not unix')
def test_customize_compiler(self):
# Make sure that sysconfig._config_vars is initialized
sysconfig.get_config_vars()
os.environ['AR'] = 'env_ar'
os.environ['CC'] = 'env_cc'
os.environ['CPP'] = 'env_cpp'
os.environ['CXX'] = 'env_cxx --env-cxx-flags'
os.environ['LDSHARED'] = 'env_ldshared'
os.environ['LDFLAGS'] = '--env-ldflags'
os.environ['ARFLAGS'] = '--env-arflags'
os.environ['CFLAGS'] = '--env-cflags'
os.environ['CPPFLAGS'] = '--env-cppflags'
comp = self.customize_compiler()
self.assertEqual(comp.exes['archiver'],
'env_ar --env-arflags')
self.assertEqual(comp.exes['preprocessor'],
'env_cpp --env-cppflags')
self.assertEqual(comp.exes['compiler'],
'env_cc --sc-cflags --env-cflags --env-cppflags')
self.assertEqual(comp.exes['compiler_so'],
('env_cc --sc-cflags '
'--env-cflags ''--env-cppflags --sc-ccshared'))
self.assertEqual(comp.exes['compiler_cxx'],
'env_cxx --env-cxx-flags')
self.assertEqual(comp.exes['linker_exe'],
'env_cc')
self.assertEqual(comp.exes['linker_so'],
('env_ldshared --env-ldflags --env-cflags'
' --env-cppflags'))
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
del os.environ['AR']
del os.environ['CC']
del os.environ['CPP']
del os.environ['CXX']
del os.environ['LDSHARED']
del os.environ['LDFLAGS']
del os.environ['ARFLAGS']
del os.environ['CFLAGS']
del os.environ['CPPFLAGS']
comp = self.customize_compiler()
self.assertEqual(comp.exes['archiver'],
'sc_ar --sc-arflags')
self.assertEqual(comp.exes['preprocessor'],
'sc_cc -E')
self.assertEqual(comp.exes['compiler'],
'sc_cc --sc-cflags')
self.assertEqual(comp.exes['compiler_so'],
'sc_cc --sc-cflags --sc-ccshared')
self.assertEqual(comp.exes['compiler_cxx'],
'sc_cxx')
self.assertEqual(comp.exes['linker_exe'],
'sc_cc')
self.assertEqual(comp.exes['linker_so'],
'sc_ldshared')
self.assertEqual(comp.shared_lib_extension, 'sc_shutil_suffix')
def test_parse_makefile_base(self):
self.makefile = test.test_support.TESTFN
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment