]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | """Tests for distutils.sysconfig."""\r |
2 | import os\r | |
3 | import test\r | |
4 | import unittest\r | |
5 | import shutil\r | |
6 | \r | |
7 | from distutils import sysconfig\r | |
8 | from distutils.tests import support\r | |
9 | from test.test_support import TESTFN\r | |
10 | \r | |
11 | class SysconfigTestCase(support.EnvironGuard,\r | |
12 | unittest.TestCase):\r | |
13 | def setUp(self):\r | |
14 | super(SysconfigTestCase, self).setUp()\r | |
15 | self.makefile = None\r | |
16 | \r | |
17 | def tearDown(self):\r | |
18 | if self.makefile is not None:\r | |
19 | os.unlink(self.makefile)\r | |
20 | self.cleanup_testfn()\r | |
21 | super(SysconfigTestCase, self).tearDown()\r | |
22 | \r | |
23 | def cleanup_testfn(self):\r | |
24 | path = test.test_support.TESTFN\r | |
25 | if os.path.isfile(path):\r | |
26 | os.remove(path)\r | |
27 | elif os.path.isdir(path):\r | |
28 | shutil.rmtree(path)\r | |
29 | \r | |
30 | def test_get_python_lib(self):\r | |
31 | lib_dir = sysconfig.get_python_lib()\r | |
32 | # XXX doesn't work on Linux when Python was never installed before\r | |
33 | #self.assertTrue(os.path.isdir(lib_dir), lib_dir)\r | |
34 | # test for pythonxx.lib?\r | |
35 | self.assertNotEqual(sysconfig.get_python_lib(),\r | |
36 | sysconfig.get_python_lib(prefix=TESTFN))\r | |
37 | _sysconfig = __import__('sysconfig')\r | |
38 | res = sysconfig.get_python_lib(True, True)\r | |
39 | self.assertEqual(_sysconfig.get_path('platstdlib'), res)\r | |
40 | \r | |
41 | def test_get_python_inc(self):\r | |
42 | inc_dir = sysconfig.get_python_inc()\r | |
43 | # This is not much of a test. We make sure Python.h exists\r | |
44 | # in the directory returned by get_python_inc() but we don't know\r | |
45 | # it is the correct file.\r | |
46 | self.assertTrue(os.path.isdir(inc_dir), inc_dir)\r | |
47 | python_h = os.path.join(inc_dir, "Python.h")\r | |
48 | self.assertTrue(os.path.isfile(python_h), python_h)\r | |
49 | \r | |
50 | def test_parse_makefile_base(self):\r | |
51 | self.makefile = test.test_support.TESTFN\r | |
52 | fd = open(self.makefile, 'w')\r | |
53 | try:\r | |
54 | fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'" '\n')\r | |
55 | fd.write('VAR=$OTHER\nOTHER=foo')\r | |
56 | finally:\r | |
57 | fd.close()\r | |
58 | d = sysconfig.parse_makefile(self.makefile)\r | |
59 | self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'",\r | |
60 | 'OTHER': 'foo'})\r | |
61 | \r | |
62 | def test_parse_makefile_literal_dollar(self):\r | |
63 | self.makefile = test.test_support.TESTFN\r | |
64 | fd = open(self.makefile, 'w')\r | |
65 | try:\r | |
66 | fd.write(r"CONFIG_ARGS= '--arg1=optarg1' 'ENV=\$$LIB'" '\n')\r | |
67 | fd.write('VAR=$OTHER\nOTHER=foo')\r | |
68 | finally:\r | |
69 | fd.close()\r | |
70 | d = sysconfig.parse_makefile(self.makefile)\r | |
71 | self.assertEqual(d, {'CONFIG_ARGS': r"'--arg1=optarg1' 'ENV=\$LIB'",\r | |
72 | 'OTHER': 'foo'})\r | |
73 | \r | |
74 | \r | |
75 | def test_suite():\r | |
76 | suite = unittest.TestSuite()\r | |
77 | suite.addTest(unittest.makeSuite(SysconfigTestCase))\r | |
78 | return suite\r | |
79 | \r | |
80 | \r | |
81 | if __name__ == '__main__':\r | |
82 | test.test_support.run_unittest(test_suite())\r |