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