test_sysconfig.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. import unittest
  2. import sys
  3. import os
  4. import subprocess
  5. import shutil
  6. from copy import copy
  7. from test.support import (
  8. captured_stdout, PythonSymlink, requires_subprocess, is_wasi
  9. )
  10. from test.support.import_helper import import_module
  11. from test.support.os_helper import (TESTFN, unlink, skip_unless_symlink,
  12. change_cwd)
  13. from test.support.warnings_helper import check_warnings
  14. import sysconfig
  15. from sysconfig import (get_paths, get_platform, get_config_vars,
  16. get_path, get_path_names, _INSTALL_SCHEMES,
  17. get_default_scheme, get_scheme_names, get_config_var,
  18. _expand_vars, _get_preferred_schemes, _main)
  19. import _osx_support
  20. HAS_USER_BASE = sysconfig._HAS_USER_BASE
  21. class TestSysConfig(unittest.TestCase):
  22. def setUp(self):
  23. super(TestSysConfig, self).setUp()
  24. self.sys_path = sys.path[:]
  25. # patching os.uname
  26. if hasattr(os, 'uname'):
  27. self.uname = os.uname
  28. self._uname = os.uname()
  29. else:
  30. self.uname = None
  31. self._set_uname(('',)*5)
  32. os.uname = self._get_uname
  33. # saving the environment
  34. self.name = os.name
  35. self.platform = sys.platform
  36. self.version = sys.version
  37. self.sep = os.sep
  38. self.join = os.path.join
  39. self.isabs = os.path.isabs
  40. self.splitdrive = os.path.splitdrive
  41. self._config_vars = sysconfig._CONFIG_VARS, copy(sysconfig._CONFIG_VARS)
  42. self._added_envvars = []
  43. self._changed_envvars = []
  44. for var in ('MACOSX_DEPLOYMENT_TARGET', 'PATH'):
  45. if var in os.environ:
  46. self._changed_envvars.append((var, os.environ[var]))
  47. else:
  48. self._added_envvars.append(var)
  49. def tearDown(self):
  50. sys.path[:] = self.sys_path
  51. self._cleanup_testfn()
  52. if self.uname is not None:
  53. os.uname = self.uname
  54. else:
  55. del os.uname
  56. os.name = self.name
  57. sys.platform = self.platform
  58. sys.version = self.version
  59. os.sep = self.sep
  60. os.path.join = self.join
  61. os.path.isabs = self.isabs
  62. os.path.splitdrive = self.splitdrive
  63. sysconfig._CONFIG_VARS = self._config_vars[0]
  64. sysconfig._CONFIG_VARS.clear()
  65. sysconfig._CONFIG_VARS.update(self._config_vars[1])
  66. for var, value in self._changed_envvars:
  67. os.environ[var] = value
  68. for var in self._added_envvars:
  69. os.environ.pop(var, None)
  70. super(TestSysConfig, self).tearDown()
  71. def _set_uname(self, uname):
  72. self._uname = os.uname_result(uname)
  73. def _get_uname(self):
  74. return self._uname
  75. def _cleanup_testfn(self):
  76. path = TESTFN
  77. if os.path.isfile(path):
  78. os.remove(path)
  79. elif os.path.isdir(path):
  80. shutil.rmtree(path)
  81. def test_get_path_names(self):
  82. self.assertEqual(get_path_names(), sysconfig._SCHEME_KEYS)
  83. def test_get_paths(self):
  84. scheme = get_paths()
  85. default_scheme = get_default_scheme()
  86. wanted = _expand_vars(default_scheme, None)
  87. wanted = sorted(wanted.items())
  88. scheme = sorted(scheme.items())
  89. self.assertEqual(scheme, wanted)
  90. def test_get_path(self):
  91. config_vars = get_config_vars()
  92. if os.name == 'nt':
  93. # On Windows, we replace the native platlibdir name with the
  94. # default so that POSIX schemes resolve correctly
  95. config_vars = config_vars | {'platlibdir': 'lib'}
  96. for scheme in _INSTALL_SCHEMES:
  97. for name in _INSTALL_SCHEMES[scheme]:
  98. expected = _INSTALL_SCHEMES[scheme][name].format(**config_vars)
  99. self.assertEqual(
  100. os.path.normpath(get_path(name, scheme)),
  101. os.path.normpath(expected),
  102. )
  103. def test_get_default_scheme(self):
  104. self.assertIn(get_default_scheme(), _INSTALL_SCHEMES)
  105. def test_get_preferred_schemes(self):
  106. expected_schemes = {'prefix', 'home', 'user'}
  107. # Windows.
  108. os.name = 'nt'
  109. schemes = _get_preferred_schemes()
  110. self.assertIsInstance(schemes, dict)
  111. self.assertEqual(set(schemes), expected_schemes)
  112. # Mac and Linux, shared library build.
  113. os.name = 'posix'
  114. schemes = _get_preferred_schemes()
  115. self.assertIsInstance(schemes, dict)
  116. self.assertEqual(set(schemes), expected_schemes)
  117. # Mac, framework build.
  118. os.name = 'posix'
  119. sys.platform = 'darwin'
  120. sys._framework = True
  121. self.assertIsInstance(schemes, dict)
  122. self.assertEqual(set(schemes), expected_schemes)
  123. def test_posix_venv_scheme(self):
  124. # The following directories were hardcoded in the venv module
  125. # before bpo-45413, here we assert the posix_venv scheme does not regress
  126. binpath = 'bin'
  127. incpath = 'include'
  128. libpath = os.path.join('lib',
  129. 'python%d.%d' % sys.version_info[:2],
  130. 'site-packages')
  131. # Resolve the paths in prefix
  132. binpath = os.path.join(sys.prefix, binpath)
  133. incpath = os.path.join(sys.prefix, incpath)
  134. libpath = os.path.join(sys.prefix, libpath)
  135. self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='posix_venv'))
  136. self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='posix_venv'))
  137. # The include directory on POSIX isn't exactly the same as before,
  138. # but it is "within"
  139. sysconfig_includedir = sysconfig.get_path('include', scheme='posix_venv')
  140. self.assertTrue(sysconfig_includedir.startswith(incpath + os.sep))
  141. def test_nt_venv_scheme(self):
  142. # The following directories were hardcoded in the venv module
  143. # before bpo-45413, here we assert the posix_venv scheme does not regress
  144. binpath = 'Scripts'
  145. incpath = 'Include'
  146. libpath = os.path.join('Lib', 'site-packages')
  147. # Resolve the paths in prefix
  148. binpath = os.path.join(sys.prefix, binpath)
  149. incpath = os.path.join(sys.prefix, incpath)
  150. libpath = os.path.join(sys.prefix, libpath)
  151. self.assertEqual(binpath, sysconfig.get_path('scripts', scheme='nt_venv'))
  152. self.assertEqual(incpath, sysconfig.get_path('include', scheme='nt_venv'))
  153. self.assertEqual(libpath, sysconfig.get_path('purelib', scheme='nt_venv'))
  154. def test_venv_scheme(self):
  155. if sys.platform == 'win32':
  156. self.assertEqual(
  157. sysconfig.get_path('scripts', scheme='venv'),
  158. sysconfig.get_path('scripts', scheme='nt_venv')
  159. )
  160. self.assertEqual(
  161. sysconfig.get_path('include', scheme='venv'),
  162. sysconfig.get_path('include', scheme='nt_venv')
  163. )
  164. self.assertEqual(
  165. sysconfig.get_path('purelib', scheme='venv'),
  166. sysconfig.get_path('purelib', scheme='nt_venv')
  167. )
  168. else:
  169. self.assertEqual(
  170. sysconfig.get_path('scripts', scheme='venv'),
  171. sysconfig.get_path('scripts', scheme='posix_venv')
  172. )
  173. self.assertEqual(
  174. sysconfig.get_path('include', scheme='venv'),
  175. sysconfig.get_path('include', scheme='posix_venv')
  176. )
  177. self.assertEqual(
  178. sysconfig.get_path('purelib', scheme='venv'),
  179. sysconfig.get_path('purelib', scheme='posix_venv')
  180. )
  181. def test_get_config_vars(self):
  182. cvars = get_config_vars()
  183. self.assertIsInstance(cvars, dict)
  184. self.assertTrue(cvars)
  185. def test_get_platform(self):
  186. # windows XP, 32bits
  187. os.name = 'nt'
  188. sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
  189. '[MSC v.1310 32 bit (Intel)]')
  190. sys.platform = 'win32'
  191. self.assertEqual(get_platform(), 'win32')
  192. # windows XP, amd64
  193. os.name = 'nt'
  194. sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
  195. '[MSC v.1310 32 bit (Amd64)]')
  196. sys.platform = 'win32'
  197. self.assertEqual(get_platform(), 'win-amd64')
  198. # macbook
  199. os.name = 'posix'
  200. sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
  201. '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
  202. sys.platform = 'darwin'
  203. self._set_uname(('Darwin', 'macziade', '8.11.1',
  204. ('Darwin Kernel Version 8.11.1: '
  205. 'Wed Oct 10 18:23:28 PDT 2007; '
  206. 'root:xnu-792.25.20~1/RELEASE_I386'), 'PowerPC'))
  207. _osx_support._remove_original_values(get_config_vars())
  208. get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
  209. get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
  210. '-fwrapv -O3 -Wall -Wstrict-prototypes')
  211. maxint = sys.maxsize
  212. try:
  213. sys.maxsize = 2147483647
  214. self.assertEqual(get_platform(), 'macosx-10.3-ppc')
  215. sys.maxsize = 9223372036854775807
  216. self.assertEqual(get_platform(), 'macosx-10.3-ppc64')
  217. finally:
  218. sys.maxsize = maxint
  219. self._set_uname(('Darwin', 'macziade', '8.11.1',
  220. ('Darwin Kernel Version 8.11.1: '
  221. 'Wed Oct 10 18:23:28 PDT 2007; '
  222. 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
  223. _osx_support._remove_original_values(get_config_vars())
  224. get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
  225. get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
  226. '-fwrapv -O3 -Wall -Wstrict-prototypes')
  227. maxint = sys.maxsize
  228. try:
  229. sys.maxsize = 2147483647
  230. self.assertEqual(get_platform(), 'macosx-10.3-i386')
  231. sys.maxsize = 9223372036854775807
  232. self.assertEqual(get_platform(), 'macosx-10.3-x86_64')
  233. finally:
  234. sys.maxsize = maxint
  235. # macbook with fat binaries (fat, universal or fat64)
  236. _osx_support._remove_original_values(get_config_vars())
  237. get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
  238. get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
  239. '/Developer/SDKs/MacOSX10.4u.sdk '
  240. '-fno-strict-aliasing -fno-common '
  241. '-dynamic -DNDEBUG -g -O3')
  242. self.assertEqual(get_platform(), 'macosx-10.4-fat')
  243. _osx_support._remove_original_values(get_config_vars())
  244. get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
  245. '/Developer/SDKs/MacOSX10.4u.sdk '
  246. '-fno-strict-aliasing -fno-common '
  247. '-dynamic -DNDEBUG -g -O3')
  248. self.assertEqual(get_platform(), 'macosx-10.4-intel')
  249. _osx_support._remove_original_values(get_config_vars())
  250. get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
  251. '/Developer/SDKs/MacOSX10.4u.sdk '
  252. '-fno-strict-aliasing -fno-common '
  253. '-dynamic -DNDEBUG -g -O3')
  254. self.assertEqual(get_platform(), 'macosx-10.4-fat3')
  255. _osx_support._remove_original_values(get_config_vars())
  256. get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
  257. '/Developer/SDKs/MacOSX10.4u.sdk '
  258. '-fno-strict-aliasing -fno-common '
  259. '-dynamic -DNDEBUG -g -O3')
  260. self.assertEqual(get_platform(), 'macosx-10.4-universal')
  261. _osx_support._remove_original_values(get_config_vars())
  262. get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
  263. '/Developer/SDKs/MacOSX10.4u.sdk '
  264. '-fno-strict-aliasing -fno-common '
  265. '-dynamic -DNDEBUG -g -O3')
  266. self.assertEqual(get_platform(), 'macosx-10.4-fat64')
  267. for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
  268. _osx_support._remove_original_values(get_config_vars())
  269. get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
  270. '/Developer/SDKs/MacOSX10.4u.sdk '
  271. '-fno-strict-aliasing -fno-common '
  272. '-dynamic -DNDEBUG -g -O3' % arch)
  273. self.assertEqual(get_platform(), 'macosx-10.4-%s' % arch)
  274. # linux debian sarge
  275. os.name = 'posix'
  276. sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) '
  277. '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
  278. sys.platform = 'linux2'
  279. self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
  280. '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
  281. self.assertEqual(get_platform(), 'linux-i686')
  282. # XXX more platforms to tests here
  283. @unittest.skipIf(is_wasi, "Incompatible with WASI mapdir and OOT builds")
  284. def test_get_config_h_filename(self):
  285. config_h = sysconfig.get_config_h_filename()
  286. self.assertTrue(os.path.isfile(config_h), config_h)
  287. def test_get_scheme_names(self):
  288. wanted = ['nt', 'posix_home', 'posix_prefix', 'posix_venv', 'nt_venv', 'venv']
  289. if HAS_USER_BASE:
  290. wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
  291. self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
  292. @skip_unless_symlink
  293. @requires_subprocess()
  294. def test_symlink(self): # Issue 7880
  295. with PythonSymlink() as py:
  296. cmd = "-c", "import sysconfig; print(sysconfig.get_platform())"
  297. self.assertEqual(py.call_real(*cmd), py.call_link(*cmd))
  298. def test_user_similar(self):
  299. # Issue #8759: make sure the posix scheme for the users
  300. # is similar to the global posix_prefix one
  301. base = get_config_var('base')
  302. if HAS_USER_BASE:
  303. user = get_config_var('userbase')
  304. # the global scheme mirrors the distinction between prefix and
  305. # exec-prefix but not the user scheme, so we have to adapt the paths
  306. # before comparing (issue #9100)
  307. adapt = sys.base_prefix != sys.base_exec_prefix
  308. for name in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
  309. global_path = get_path(name, 'posix_prefix')
  310. if adapt:
  311. global_path = global_path.replace(sys.exec_prefix, sys.base_prefix)
  312. base = base.replace(sys.exec_prefix, sys.base_prefix)
  313. elif sys.base_prefix != sys.prefix:
  314. # virtual environment? Likewise, we have to adapt the paths
  315. # before comparing
  316. global_path = global_path.replace(sys.base_prefix, sys.prefix)
  317. base = base.replace(sys.base_prefix, sys.prefix)
  318. if HAS_USER_BASE:
  319. user_path = get_path(name, 'posix_user')
  320. expected = os.path.normpath(global_path.replace(base, user, 1))
  321. # bpo-44860: platlib of posix_user doesn't use sys.platlibdir,
  322. # whereas posix_prefix does.
  323. if name == 'platlib':
  324. # Replace "/lib64/python3.11/site-packages" suffix
  325. # with "/lib/python3.11/site-packages".
  326. py_version_short = sysconfig.get_python_version()
  327. suffix = f'python{py_version_short}/site-packages'
  328. expected = expected.replace(f'/{sys.platlibdir}/{suffix}',
  329. f'/lib/{suffix}')
  330. self.assertEqual(user_path, expected)
  331. def test_main(self):
  332. # just making sure _main() runs and returns things in the stdout
  333. with captured_stdout() as output:
  334. _main()
  335. self.assertTrue(len(output.getvalue().split('\n')) > 0)
  336. @unittest.skipIf(sys.platform == "win32", "Does not apply to Windows")
  337. def test_ldshared_value(self):
  338. ldflags = sysconfig.get_config_var('LDFLAGS')
  339. ldshared = sysconfig.get_config_var('LDSHARED')
  340. self.assertIn(ldflags, ldshared)
  341. @unittest.skipUnless(sys.platform == "darwin", "test only relevant on MacOSX")
  342. @requires_subprocess()
  343. def test_platform_in_subprocess(self):
  344. my_platform = sysconfig.get_platform()
  345. # Test without MACOSX_DEPLOYMENT_TARGET in the environment
  346. env = os.environ.copy()
  347. if 'MACOSX_DEPLOYMENT_TARGET' in env:
  348. del env['MACOSX_DEPLOYMENT_TARGET']
  349. p = subprocess.Popen([
  350. sys.executable, '-c',
  351. 'import sysconfig; print(sysconfig.get_platform())',
  352. ],
  353. stdout=subprocess.PIPE,
  354. stderr=subprocess.DEVNULL,
  355. env=env)
  356. test_platform = p.communicate()[0].strip()
  357. test_platform = test_platform.decode('utf-8')
  358. status = p.wait()
  359. self.assertEqual(status, 0)
  360. self.assertEqual(my_platform, test_platform)
  361. # Test with MACOSX_DEPLOYMENT_TARGET in the environment, and
  362. # using a value that is unlikely to be the default one.
  363. env = os.environ.copy()
  364. env['MACOSX_DEPLOYMENT_TARGET'] = '10.1'
  365. p = subprocess.Popen([
  366. sys.executable, '-c',
  367. 'import sysconfig; print(sysconfig.get_platform())',
  368. ],
  369. stdout=subprocess.PIPE,
  370. stderr=subprocess.DEVNULL,
  371. env=env)
  372. test_platform = p.communicate()[0].strip()
  373. test_platform = test_platform.decode('utf-8')
  374. status = p.wait()
  375. self.assertEqual(status, 0)
  376. self.assertEqual(my_platform, test_platform)
  377. @unittest.skipIf(is_wasi, "Incompatible with WASI mapdir and OOT builds")
  378. def test_srcdir(self):
  379. # See Issues #15322, #15364.
  380. srcdir = sysconfig.get_config_var('srcdir')
  381. self.assertTrue(os.path.isabs(srcdir), srcdir)
  382. self.assertTrue(os.path.isdir(srcdir), srcdir)
  383. if sysconfig._PYTHON_BUILD:
  384. # The python executable has not been installed so srcdir
  385. # should be a full source checkout.
  386. Python_h = os.path.join(srcdir, 'Include', 'Python.h')
  387. self.assertTrue(os.path.exists(Python_h), Python_h)
  388. # <srcdir>/PC/pyconfig.h always exists even if unused on POSIX.
  389. pyconfig_h = os.path.join(srcdir, 'PC', 'pyconfig.h')
  390. self.assertTrue(os.path.exists(pyconfig_h), pyconfig_h)
  391. pyconfig_h_in = os.path.join(srcdir, 'pyconfig.h.in')
  392. self.assertTrue(os.path.exists(pyconfig_h_in), pyconfig_h_in)
  393. elif os.name == 'posix':
  394. makefile_dir = os.path.dirname(sysconfig.get_makefile_filename())
  395. # Issue #19340: srcdir has been realpath'ed already
  396. makefile_dir = os.path.realpath(makefile_dir)
  397. self.assertEqual(makefile_dir, srcdir)
  398. def test_srcdir_independent_of_cwd(self):
  399. # srcdir should be independent of the current working directory
  400. # See Issues #15322, #15364.
  401. srcdir = sysconfig.get_config_var('srcdir')
  402. with change_cwd(os.pardir):
  403. srcdir2 = sysconfig.get_config_var('srcdir')
  404. self.assertEqual(srcdir, srcdir2)
  405. @unittest.skipIf(sysconfig.get_config_var('EXT_SUFFIX') is None,
  406. 'EXT_SUFFIX required for this test')
  407. def test_EXT_SUFFIX_in_vars(self):
  408. import _imp
  409. if not _imp.extension_suffixes():
  410. self.skipTest("stub loader has no suffixes")
  411. vars = sysconfig.get_config_vars()
  412. self.assertEqual(vars['EXT_SUFFIX'], _imp.extension_suffixes()[0])
  413. @unittest.skipUnless(sys.platform == 'linux' and
  414. hasattr(sys.implementation, '_multiarch'),
  415. 'multiarch-specific test')
  416. def test_triplet_in_ext_suffix(self):
  417. ctypes = import_module('ctypes')
  418. import platform, re
  419. machine = platform.machine()
  420. suffix = sysconfig.get_config_var('EXT_SUFFIX')
  421. if re.match('(aarch64|arm|mips|ppc|powerpc|s390|sparc)', machine):
  422. self.assertTrue('linux' in suffix, suffix)
  423. if re.match('(i[3-6]86|x86_64)$', machine):
  424. if ctypes.sizeof(ctypes.c_char_p()) == 4:
  425. expected_suffixes = 'i386-linux-gnu.so', 'x86_64-linux-gnux32.so', 'i386-linux-musl.so'
  426. else: # 8 byte pointer size
  427. expected_suffixes = 'x86_64-linux-gnu.so', 'x86_64-linux-musl.so'
  428. self.assertTrue(suffix.endswith(expected_suffixes),
  429. f'unexpected suffix {suffix!r}')
  430. @unittest.skipUnless(sys.platform == 'darwin', 'OS X-specific test')
  431. def test_osx_ext_suffix(self):
  432. suffix = sysconfig.get_config_var('EXT_SUFFIX')
  433. self.assertTrue(suffix.endswith('-darwin.so'), suffix)
  434. class MakefileTests(unittest.TestCase):
  435. @unittest.skipIf(sys.platform.startswith('win'),
  436. 'Test is not Windows compatible')
  437. @unittest.skipIf(is_wasi, "Incompatible with WASI mapdir and OOT builds")
  438. def test_get_makefile_filename(self):
  439. makefile = sysconfig.get_makefile_filename()
  440. self.assertTrue(os.path.isfile(makefile), makefile)
  441. def test_parse_makefile(self):
  442. self.addCleanup(unlink, TESTFN)
  443. with open(TESTFN, "w") as makefile:
  444. print("var1=a$(VAR2)", file=makefile)
  445. print("VAR2=b$(var3)", file=makefile)
  446. print("var3=42", file=makefile)
  447. print("var4=$/invalid", file=makefile)
  448. print("var5=dollar$$5", file=makefile)
  449. print("var6=${var3}/lib/python3.5/config-$(VAR2)$(var5)"
  450. "-x86_64-linux-gnu", file=makefile)
  451. vars = sysconfig._parse_makefile(TESTFN)
  452. self.assertEqual(vars, {
  453. 'var1': 'ab42',
  454. 'VAR2': 'b42',
  455. 'var3': 42,
  456. 'var4': '$/invalid',
  457. 'var5': 'dollar$5',
  458. 'var6': '42/lib/python3.5/config-b42dollar$5-x86_64-linux-gnu',
  459. })
  460. if __name__ == "__main__":
  461. unittest.main()