2009-05-10 08:59:30 -03:00
|
|
|
"""Tests for distutils.sysconfig."""
|
2007-12-06 09:15:13 -04:00
|
|
|
import os
|
2009-06-11 05:12:20 -03:00
|
|
|
import test
|
2007-12-06 09:15:13 -04:00
|
|
|
import unittest
|
2010-02-06 19:53:52 -04:00
|
|
|
import shutil
|
2014-07-06 20:11:44 -03:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import textwrap
|
2007-12-06 09:15:13 -04:00
|
|
|
|
2009-05-10 08:59:30 -03:00
|
|
|
from distutils import sysconfig
|
|
|
|
from distutils.tests import support
|
2007-12-06 09:15:13 -04:00
|
|
|
from test.test_support import TESTFN
|
|
|
|
|
2009-05-10 08:59:30 -03:00
|
|
|
class SysconfigTestCase(support.EnvironGuard,
|
|
|
|
unittest.TestCase):
|
2009-06-11 05:12:20 -03:00
|
|
|
def setUp(self):
|
|
|
|
super(SysconfigTestCase, self).setUp()
|
|
|
|
self.makefile = None
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
if self.makefile is not None:
|
|
|
|
os.unlink(self.makefile)
|
2009-10-18 06:28:26 -03:00
|
|
|
self.cleanup_testfn()
|
2009-06-11 05:12:20 -03:00
|
|
|
super(SysconfigTestCase, self).tearDown()
|
2009-02-05 21:15:51 -04:00
|
|
|
|
2009-10-18 06:28:26 -03:00
|
|
|
def cleanup_testfn(self):
|
|
|
|
path = test.test_support.TESTFN
|
|
|
|
if os.path.isfile(path):
|
|
|
|
os.remove(path)
|
|
|
|
elif os.path.isdir(path):
|
|
|
|
shutil.rmtree(path)
|
|
|
|
|
2007-12-06 09:15:13 -04:00
|
|
|
def test_get_python_lib(self):
|
|
|
|
lib_dir = sysconfig.get_python_lib()
|
2007-12-14 19:42:36 -04:00
|
|
|
# XXX doesn't work on Linux when Python was never installed before
|
2009-06-30 19:57:08 -03:00
|
|
|
#self.assertTrue(os.path.isdir(lib_dir), lib_dir)
|
2007-12-06 09:15:13 -04:00
|
|
|
# test for pythonxx.lib?
|
2009-02-10 08:31:09 -04:00
|
|
|
self.assertNotEqual(sysconfig.get_python_lib(),
|
|
|
|
sysconfig.get_python_lib(prefix=TESTFN))
|
2010-01-23 05:23:15 -04:00
|
|
|
_sysconfig = __import__('sysconfig')
|
|
|
|
res = sysconfig.get_python_lib(True, True)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(_sysconfig.get_path('platstdlib'), res)
|
2007-12-06 09:15:13 -04:00
|
|
|
|
|
|
|
def test_get_python_inc(self):
|
2009-02-05 12:19:05 -04:00
|
|
|
inc_dir = sysconfig.get_python_inc()
|
|
|
|
# This is not much of a test. We make sure Python.h exists
|
|
|
|
# in the directory returned by get_python_inc() but we don't know
|
|
|
|
# it is the correct file.
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(os.path.isdir(inc_dir), inc_dir)
|
2007-12-06 09:15:13 -04:00
|
|
|
python_h = os.path.join(inc_dir, "Python.h")
|
2009-06-30 19:57:08 -03:00
|
|
|
self.assertTrue(os.path.isfile(python_h), python_h)
|
2007-12-06 09:15:13 -04:00
|
|
|
|
2009-06-11 05:12:20 -03:00
|
|
|
def test_parse_makefile_base(self):
|
|
|
|
self.makefile = test.test_support.TESTFN
|
|
|
|
fd = open(self.makefile, 'w')
|
2010-11-06 01:06:18 -03:00
|
|
|
try:
|
|
|
|
fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
|
|
|
|
fd.write('VAR=$OTHER\nOTHER=foo')
|
|
|
|
finally:
|
|
|
|
fd.close()
|
2009-06-11 05:12:20 -03:00
|
|
|
d = sysconfig.parse_makefile(self.makefile)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
|
|
|
|
'OTHER': 'foo'})
|
2009-06-11 05:12:20 -03:00
|
|
|
|
|
|
|
def test_parse_makefile_literal_dollar(self):
|
|
|
|
self.makefile = test.test_support.TESTFN
|
|
|
|
fd = open(self.makefile, 'w')
|
2010-11-06 01:06:18 -03:00
|
|
|
try:
|
|
|
|
fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
|
|
|
|
fd.write('VAR=$OTHER\nOTHER=foo')
|
|
|
|
finally:
|
|
|
|
fd.close()
|
2009-06-11 05:12:20 -03:00
|
|
|
d = sysconfig.parse_makefile(self.makefile)
|
2010-11-21 09:34:58 -04:00
|
|
|
self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
|
|
|
|
'OTHER': 'foo'})
|
2009-06-11 05:12:20 -03:00
|
|
|
|
2007-12-06 09:15:13 -04:00
|
|
|
|
2013-01-31 05:24:55 -04:00
|
|
|
def test_sysconfig_module(self):
|
|
|
|
import sysconfig as global_sysconfig
|
|
|
|
self.assertEqual(global_sysconfig.get_config_var('CFLAGS'), sysconfig.get_config_var('CFLAGS'))
|
|
|
|
self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'), sysconfig.get_config_var('LDFLAGS'))
|
|
|
|
|
|
|
|
@unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),'compiler flags customized')
|
|
|
|
def test_sysconfig_compiler_vars(self):
|
|
|
|
# On OS X, binary installers support extension module building on
|
|
|
|
# various levels of the operating system with differing Xcode
|
|
|
|
# configurations. This requires customization of some of the
|
|
|
|
# compiler configuration directives to suit the environment on
|
|
|
|
# the installed machine. Some of these customizations may require
|
|
|
|
# running external programs and, so, are deferred until needed by
|
|
|
|
# the first extension module build. With Python 3.3, only
|
|
|
|
# the Distutils version of sysconfig is used for extension module
|
|
|
|
# builds, which happens earlier in the Distutils tests. This may
|
|
|
|
# cause the following tests to fail since no tests have caused
|
|
|
|
# the global version of sysconfig to call the customization yet.
|
|
|
|
# The solution for now is to simply skip this test in this case.
|
|
|
|
# The longer-term solution is to only have one version of sysconfig.
|
|
|
|
|
|
|
|
import sysconfig as global_sysconfig
|
|
|
|
if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
2013-12-18 10:45:37 -04:00
|
|
|
self.skipTest('compiler flags customized')
|
2013-01-31 05:24:55 -04:00
|
|
|
self.assertEqual(global_sysconfig.get_config_var('LDSHARED'), sysconfig.get_config_var('LDSHARED'))
|
|
|
|
self.assertEqual(global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC'))
|
|
|
|
|
2014-07-06 20:11:44 -03:00
|
|
|
def test_customize_compiler_before_get_config_vars(self):
|
|
|
|
# Issue #21923: test that a Distribution compiler
|
|
|
|
# instance can be called without an explicit call to
|
|
|
|
# get_config_vars().
|
|
|
|
with open(TESTFN, 'w') as f:
|
|
|
|
f.writelines(textwrap.dedent('''\
|
|
|
|
from distutils.core import Distribution
|
|
|
|
config = Distribution().get_command_obj('config')
|
|
|
|
# try_compile may pass or it may fail if no compiler
|
|
|
|
# is found but it should not raise an exception.
|
|
|
|
rc = config.try_compile('int x;')
|
|
|
|
'''))
|
|
|
|
p = subprocess.Popen([str(sys.executable), TESTFN],
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.STDOUT,
|
|
|
|
universal_newlines=True)
|
|
|
|
outs, errs = p.communicate()
|
|
|
|
self.assertEqual(0, p.returncode, "Subprocess failed: " + outs)
|
2013-01-31 05:24:55 -04:00
|
|
|
|
|
|
|
|
2007-12-06 09:15:13 -04:00
|
|
|
def test_suite():
|
|
|
|
suite = unittest.TestSuite()
|
|
|
|
suite.addTest(unittest.makeSuite(SysconfigTestCase))
|
|
|
|
return suite
|
2009-06-11 05:12:20 -03:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test.test_support.run_unittest(test_suite())
|