]>
git.proxmox.com Git - mirror_edk2.git/blob - AppPkg/Applications/Python/Python-2.7.2/Lib/test/test_sysconfig.py
3 Tests assume the initial paths in sys.path once the interpreter has begun
4 executing have not been removed.
12 from copy
import copy
, deepcopy
14 from test
.test_support
import run_unittest
, TESTFN
, unlink
, get_attribute
17 from sysconfig
import (get_paths
, get_platform
, get_config_vars
,
18 get_path
, get_path_names
, _INSTALL_SCHEMES
,
19 _get_default_scheme
, _expand_vars
,
20 get_scheme_names
, get_config_var
)
22 class TestSysConfig(unittest
.TestCase
):
25 """Make a copy of sys.path"""
26 super(TestSysConfig
, self
).setUp()
27 self
.sys_path
= sys
.path
[:]
30 if hasattr(os
, 'uname'):
32 self
._uname
= os
.uname()
36 os
.uname
= self
._get
_uname
37 # saving the environment
39 self
.platform
= sys
.platform
40 self
.version
= sys
.version
42 self
.join
= os
.path
.join
43 self
.isabs
= os
.path
.isabs
44 self
.splitdrive
= os
.path
.splitdrive
45 self
._config
_vars
= copy(sysconfig
._CONFIG
_VARS
)
46 self
.old_environ
= deepcopy(os
.environ
)
49 """Restore sys.path"""
50 sys
.path
[:] = self
.sys_path
51 if self
.makefile
is not None:
52 os
.unlink(self
.makefile
)
53 self
._cleanup
_testfn
()
54 if self
.uname
is not None:
59 sys
.platform
= self
.platform
60 sys
.version
= self
.version
62 os
.path
.join
= self
.join
63 os
.path
.isabs
= self
.isabs
64 os
.path
.splitdrive
= self
.splitdrive
65 sysconfig
._CONFIG
_VARS
= copy(self
._config
_vars
)
66 for key
, value
in self
.old_environ
.items():
67 if os
.environ
.get(key
) != value
:
68 os
.environ
[key
] = value
70 for key
in os
.environ
.keys():
71 if key
not in self
.old_environ
:
74 super(TestSysConfig
, self
).tearDown()
76 def _set_uname(self
, uname
):
82 def _cleanup_testfn(self
):
84 if os
.path
.isfile(path
):
86 elif os
.path
.isdir(path
):
89 def test_get_path_names(self
):
90 self
.assertEqual(get_path_names(), sysconfig
._SCHEME
_KEYS
)
92 def test_get_paths(self
):
94 default_scheme
= _get_default_scheme()
95 wanted
= _expand_vars(default_scheme
, None)
96 wanted
= wanted
.items()
98 scheme
= scheme
.items()
100 self
.assertEqual(scheme
, wanted
)
102 def test_get_path(self
):
103 # xxx make real tests here
104 for scheme
in _INSTALL_SCHEMES
:
105 for name
in _INSTALL_SCHEMES
[scheme
]:
106 res
= get_path(name
, scheme
)
108 def test_get_config_vars(self
):
109 cvars
= get_config_vars()
110 self
.assertIsInstance(cvars
, dict)
111 self
.assertTrue(cvars
)
113 def test_get_platform(self
):
116 sys
.version
= ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
117 '[MSC v.1310 32 bit (Intel)]')
118 sys
.platform
= 'win32'
119 self
.assertEqual(get_platform(), 'win32')
123 sys
.version
= ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
124 '[MSC v.1310 32 bit (Amd64)]')
125 sys
.platform
= 'win32'
126 self
.assertEqual(get_platform(), 'win-amd64')
128 # windows XP, itanium
130 sys
.version
= ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
131 '[MSC v.1310 32 bit (Itanium)]')
132 sys
.platform
= 'win32'
133 self
.assertEqual(get_platform(), 'win-ia64')
137 sys
.version
= ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
138 '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
139 sys
.platform
= 'darwin'
140 self
._set
_uname
(('Darwin', 'macziade', '8.11.1',
141 ('Darwin Kernel Version 8.11.1: '
142 'Wed Oct 10 18:23:28 PDT 2007; '
143 'root:xnu-792.25.20~1/RELEASE_I386'), 'PowerPC'))
144 get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
146 get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
147 '-fwrapv -O3 -Wall -Wstrict-prototypes')
151 sys
.maxint
= 2147483647
152 self
.assertEqual(get_platform(), 'macosx-10.3-ppc')
153 sys
.maxint
= 9223372036854775807
154 self
.assertEqual(get_platform(), 'macosx-10.3-ppc64')
159 self
._set
_uname
(('Darwin', 'macziade', '8.11.1',
160 ('Darwin Kernel Version 8.11.1: '
161 'Wed Oct 10 18:23:28 PDT 2007; '
162 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
163 get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
165 get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
166 '-fwrapv -O3 -Wall -Wstrict-prototypes')
170 sys
.maxint
= 2147483647
171 self
.assertEqual(get_platform(), 'macosx-10.3-i386')
172 sys
.maxint
= 9223372036854775807
173 self
.assertEqual(get_platform(), 'macosx-10.3-x86_64')
177 # macbook with fat binaries (fat, universal or fat64)
178 get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
179 get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
180 '/Developer/SDKs/MacOSX10.4u.sdk '
181 '-fno-strict-aliasing -fno-common '
182 '-dynamic -DNDEBUG -g -O3')
184 self
.assertEqual(get_platform(), 'macosx-10.4-fat')
186 get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
187 '/Developer/SDKs/MacOSX10.4u.sdk '
188 '-fno-strict-aliasing -fno-common '
189 '-dynamic -DNDEBUG -g -O3')
191 self
.assertEqual(get_platform(), 'macosx-10.4-intel')
193 get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
194 '/Developer/SDKs/MacOSX10.4u.sdk '
195 '-fno-strict-aliasing -fno-common '
196 '-dynamic -DNDEBUG -g -O3')
197 self
.assertEqual(get_platform(), 'macosx-10.4-fat3')
199 get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
200 '/Developer/SDKs/MacOSX10.4u.sdk '
201 '-fno-strict-aliasing -fno-common '
202 '-dynamic -DNDEBUG -g -O3')
203 self
.assertEqual(get_platform(), 'macosx-10.4-universal')
205 get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
206 '/Developer/SDKs/MacOSX10.4u.sdk '
207 '-fno-strict-aliasing -fno-common '
208 '-dynamic -DNDEBUG -g -O3')
210 self
.assertEqual(get_platform(), 'macosx-10.4-fat64')
212 for arch
in ('ppc', 'i386', 'x86_64', 'ppc64'):
213 get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
214 '/Developer/SDKs/MacOSX10.4u.sdk '
215 '-fno-strict-aliasing -fno-common '
216 '-dynamic -DNDEBUG -g -O3'%(arch
,))
218 self
.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch
,))
222 sys
.version
= ('2.3.5 (#1, Jul 4 2007, 17:28:59) '
223 '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
224 sys
.platform
= 'linux2'
225 self
._set
_uname
(('Linux', 'aglae', '2.6.21.1dedibox-r7',
226 '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
228 self
.assertEqual(get_platform(), 'linux-i686')
230 # XXX more platforms to tests here
232 def test_get_config_h_filename(self
):
233 config_h
= sysconfig
.get_config_h_filename()
234 self
.assertTrue(os
.path
.isfile(config_h
), config_h
)
236 def test_get_scheme_names(self
):
237 wanted
= ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user',
238 'posix_home', 'posix_prefix', 'posix_user')
239 self
.assertEqual(get_scheme_names(), wanted
)
241 def test_symlink(self
):
243 symlink
= get_attribute(os
, "symlink")
246 'import sysconfig; print sysconfig.get_platform()']
247 p
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
)
248 return p
.communicate()
249 real
= os
.path
.realpath(sys
.executable
)
250 link
= os
.path
.abspath(TESTFN
)
253 self
.assertEqual(get(real
), get(link
))
257 def test_user_similar(self
):
258 # Issue 8759 : make sure the posix scheme for the users
259 # is similar to the global posix_prefix one
260 base
= get_config_var('base')
261 user
= get_config_var('userbase')
262 for name
in ('stdlib', 'platstdlib', 'purelib', 'platlib'):
263 global_path
= get_path(name
, 'posix_prefix')
264 user_path
= get_path(name
, 'posix_user')
265 self
.assertEqual(user_path
, global_path
.replace(base
, user
))
267 @unittest.skipUnless(sys
.platform
== "darwin", "test only relevant on MacOSX")
268 def test_platform_in_subprocess(self
):
269 my_platform
= sysconfig
.get_platform()
271 # Test without MACOSX_DEPLOYMENT_TARGET in the environment
273 env
= os
.environ
.copy()
274 if 'MACOSX_DEPLOYMENT_TARGET' in env
:
275 del env
['MACOSX_DEPLOYMENT_TARGET']
277 with
open('/dev/null', 'w') as devnull_fp
:
278 p
= subprocess
.Popen([
279 sys
.executable
, '-c',
280 'import sysconfig; print(sysconfig.get_platform())',
282 stdout
=subprocess
.PIPE
,
285 test_platform
= p
.communicate()[0].strip()
286 test_platform
= test_platform
.decode('utf-8')
289 self
.assertEqual(status
, 0)
290 self
.assertEqual(my_platform
, test_platform
)
293 # Test with MACOSX_DEPLOYMENT_TARGET in the environment, and
294 # using a value that is unlikely to be the default one.
295 env
= os
.environ
.copy()
296 env
['MACOSX_DEPLOYMENT_TARGET'] = '10.1'
298 p
= subprocess
.Popen([
299 sys
.executable
, '-c',
300 'import sysconfig; print(sysconfig.get_platform())',
302 stdout
=subprocess
.PIPE
,
303 stderr
=open('/dev/null'),
305 test_platform
= p
.communicate()[0].strip()
306 test_platform
= test_platform
.decode('utf-8')
309 self
.assertEqual(status
, 0)
310 self
.assertEqual(my_platform
, test_platform
)
313 run_unittest(TestSysConfig
)
315 if __name__
== "__main__":