1 | """Tests for distutils.sysconfig."""
|
---|
2 | import os
|
---|
3 | import test
|
---|
4 | import unittest
|
---|
5 | import shutil
|
---|
6 |
|
---|
7 | from distutils import sysconfig
|
---|
8 | from distutils.tests import support
|
---|
9 | from test.test_support import TESTFN
|
---|
10 |
|
---|
11 | class SysconfigTestCase(support.EnvironGuard,
|
---|
12 | unittest.TestCase):
|
---|
13 | def setUp(self):
|
---|
14 | super(SysconfigTestCase, self).setUp()
|
---|
15 | self.makefile = None
|
---|
16 |
|
---|
17 | def tearDown(self):
|
---|
18 | if self.makefile is not None:
|
---|
19 | os.unlink(self.makefile)
|
---|
20 | self.cleanup_testfn()
|
---|
21 | super(SysconfigTestCase, self).tearDown()
|
---|
22 |
|
---|
23 | def cleanup_testfn(self):
|
---|
24 | path = test.test_support.TESTFN
|
---|
25 | if os.path.isfile(path):
|
---|
26 | os.remove(path)
|
---|
27 | elif os.path.isdir(path):
|
---|
28 | shutil.rmtree(path)
|
---|
29 |
|
---|
30 | def test_get_python_lib(self):
|
---|
31 | lib_dir = sysconfig.get_python_lib()
|
---|
32 | # XXX doesn't work on Linux when Python was never installed before
|
---|
33 | #self.assertTrue(os.path.isdir(lib_dir), lib_dir)
|
---|
34 | # test for pythonxx.lib?
|
---|
35 | self.assertNotEqual(sysconfig.get_python_lib(),
|
---|
36 | sysconfig.get_python_lib(prefix=TESTFN))
|
---|
37 | _sysconfig = __import__('sysconfig')
|
---|
38 | res = sysconfig.get_python_lib(True, True)
|
---|
39 | self.assertEqual(_sysconfig.get_path('platstdlib'), res)
|
---|
40 |
|
---|
41 | def test_get_python_inc(self):
|
---|
42 | inc_dir = sysconfig.get_python_inc()
|
---|
43 | # This is not much of a test. We make sure Python.h exists
|
---|
44 | # in the directory returned by get_python_inc() but we don't know
|
---|
45 | # it is the correct file.
|
---|
46 | self.assertTrue(os.path.isdir(inc_dir), inc_dir)
|
---|
47 | python_h = os.path.join(inc_dir, "Python.h")
|
---|
48 | self.assertTrue(os.path.isfile(python_h), python_h)
|
---|
49 |
|
---|
50 | def test_parse_makefile_base(self):
|
---|
51 | self.makefile = test.test_support.TESTFN
|
---|
52 | fd = open(self.makefile, 'w')
|
---|
53 | try:
|
---|
54 | fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')
|
---|
55 | fd.write('VAR=$OTHER\nOTHER=foo')
|
---|
56 | finally:
|
---|
57 | fd.close()
|
---|
58 | d = sysconfig.parse_makefile(self.makefile)
|
---|
59 | self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",
|
---|
60 | 'OTHER': 'foo'})
|
---|
61 |
|
---|
62 | def test_parse_makefile_literal_dollar(self):
|
---|
63 | self.makefile = test.test_support.TESTFN
|
---|
64 | fd = open(self.makefile, 'w')
|
---|
65 | try:
|
---|
66 | fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')
|
---|
67 | fd.write('VAR=$OTHER\nOTHER=foo')
|
---|
68 | finally:
|
---|
69 | fd.close()
|
---|
70 | d = sysconfig.parse_makefile(self.makefile)
|
---|
71 | self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",
|
---|
72 | 'OTHER': 'foo'})
|
---|
73 |
|
---|
74 |
|
---|
75 | def test_sysconfig_module(self):
|
---|
76 | import sysconfig as global_sysconfig
|
---|
77 | self.assertEqual(global_sysconfig.get_config_var('CFLAGS'), sysconfig.get_config_var('CFLAGS'))
|
---|
78 | self.assertEqual(global_sysconfig.get_config_var('LDFLAGS'), sysconfig.get_config_var('LDFLAGS'))
|
---|
79 |
|
---|
80 | @unittest.skipIf(sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'),'compiler flags customized')
|
---|
81 | def test_sysconfig_compiler_vars(self):
|
---|
82 | # On OS X, binary installers support extension module building on
|
---|
83 | # various levels of the operating system with differing Xcode
|
---|
84 | # configurations. This requires customization of some of the
|
---|
85 | # compiler configuration directives to suit the environment on
|
---|
86 | # the installed machine. Some of these customizations may require
|
---|
87 | # running external programs and, so, are deferred until needed by
|
---|
88 | # the first extension module build. With Python 3.3, only
|
---|
89 | # the Distutils version of sysconfig is used for extension module
|
---|
90 | # builds, which happens earlier in the Distutils tests. This may
|
---|
91 | # cause the following tests to fail since no tests have caused
|
---|
92 | # the global version of sysconfig to call the customization yet.
|
---|
93 | # The solution for now is to simply skip this test in this case.
|
---|
94 | # The longer-term solution is to only have one version of sysconfig.
|
---|
95 |
|
---|
96 | import sysconfig as global_sysconfig
|
---|
97 | if sysconfig.get_config_var('CUSTOMIZED_OSX_COMPILER'):
|
---|
98 | return
|
---|
99 | self.assertEqual(global_sysconfig.get_config_var('LDSHARED'), sysconfig.get_config_var('LDSHARED'))
|
---|
100 | self.assertEqual(global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC'))
|
---|
101 |
|
---|
102 |
|
---|
103 |
|
---|
104 | def test_suite():
|
---|
105 | suite = unittest.TestSuite()
|
---|
106 | suite.addTest(unittest.makeSuite(SysconfigTestCase))
|
---|
107 | return suite
|
---|
108 |
|
---|
109 |
|
---|
110 | if __name__ == '__main__':
|
---|
111 | test.test_support.run_unittest(test_suite())
|
---|