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