test_sysconfig.py (2537B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\tests\test_sysconfig.py 2 import os 3 import test 4 import unittest 5 import shutil 6 from distutils import sysconfig 7 from distutils.tests import support 8 from test.test_support import TESTFN 9 10 class SysconfigTestCase(support.EnvironGuard, unittest.TestCase): 11 12 def setUp(self): 13 super(SysconfigTestCase, self).setUp() 14 self.makefile = None 15 16 def tearDown(self): 17 if self.makefile is not None: 18 os.unlink(self.makefile) 19 self.cleanup_testfn() 20 super(SysconfigTestCase, self).tearDown() 21 22 def cleanup_testfn(self): 23 path = test.test_support.TESTFN 24 if os.path.isfile(path): 25 os.remove(path) 26 elif os.path.isdir(path): 27 shutil.rmtree(path) 28 29 def test_get_python_lib(self): 30 lib_dir = sysconfig.get_python_lib() 31 self.assertNotEqual(sysconfig.get_python_lib(), sysconfig.get_python_lib(prefix=TESTFN)) 32 _sysconfig = __import__('sysconfig') 33 res = sysconfig.get_python_lib(True, True) 34 self.assertEqual(_sysconfig.get_path('platstdlib'), res) 35 36 def test_get_python_inc(self): 37 inc_dir = sysconfig.get_python_inc() 38 self.assertTrue(os.path.isdir(inc_dir), inc_dir) 39 python_h = os.path.join(inc_dir, 'Python.h') 40 self.assertTrue(os.path.isfile(python_h), python_h) 41 42 def test_parse_makefile_base(self): 43 self.makefile = test.test_support.TESTFN 44 fd = open(self.makefile, 'w') 45 try: 46 fd.write("CONFIG_ARGS= '--arg1=optarg1' 'ENV=LIB'\n") 47 fd.write('VAR=$OTHER\nOTHER=foo') 48 finally: 49 fd.close() 50 51 d = sysconfig.parse_makefile(self.makefile) 52 self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=LIB'", 53 'OTHER': 'foo'}) 54 55 def test_parse_makefile_literal_dollar(self): 56 self.makefile = test.test_support.TESTFN 57 fd = open(self.makefile, 'w') 58 try: 59 fd.write("CONFIG_ARGS= '--arg1=optarg1' 'ENV=\\$$LIB'\n") 60 fd.write('VAR=$OTHER\nOTHER=foo') 61 finally: 62 fd.close() 63 64 d = sysconfig.parse_makefile(self.makefile) 65 self.assertEqual(d, {'CONFIG_ARGS': "'--arg1=optarg1' 'ENV=\\$LIB'", 66 'OTHER': 'foo'}) 67 68 69 def test_suite(): 70 suite = unittest.TestSuite() 71 suite.addTest(unittest.makeSuite(SysconfigTestCase)) 72 return suite 73 74 75 if __name__ == '__main__': 76 test.test_support.run_unittest(test_suite())