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 | |
Éric Araujo | de50455 | 2011-10-08 01:55:07 +0200 | [diff] [blame] | 8 | from test.support import (run_unittest, TESTFN, unlink, |
Brian Curtin | 3b4499c | 2010-12-28 14:31:47 +0000 | [diff] [blame] | 9 | captured_stdout, skip_unless_symlink) |
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): |
Benjamin Peterson | 3c451e6 | 2010-05-08 15:51:23 +0000 | [diff] [blame] | 237 | wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user', |
| 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 | |
| 308 | with open('/dev/null', 'w') as devnull_fp: |
| 309 | p = subprocess.Popen([ |
| 310 | sys.executable, '-c', |
| 311 | 'import sysconfig; print(sysconfig.get_platform())', |
| 312 | ], |
| 313 | stdout=subprocess.PIPE, |
| 314 | stderr=devnull_fp, |
| 315 | env=env) |
| 316 | test_platform = p.communicate()[0].strip() |
| 317 | test_platform = test_platform.decode('utf-8') |
| 318 | status = p.wait() |
| 319 | |
| 320 | self.assertEqual(status, 0) |
| 321 | self.assertEqual(my_platform, test_platform) |
| 322 | |
Ronald Oussoren | 222e89a | 2011-05-15 16:46:11 +0200 | [diff] [blame] | 323 | # Test with MACOSX_DEPLOYMENT_TARGET in the environment, and |
| 324 | # using a value that is unlikely to be the default one. |
| 325 | env = os.environ.copy() |
| 326 | env['MACOSX_DEPLOYMENT_TARGET'] = '10.1' |
| 327 | |
Brett Cannon | a426554 | 2011-08-04 21:34:52 -0700 | [diff] [blame] | 328 | with open('/dev/null') as dev_null: |
| 329 | p = subprocess.Popen([ |
| 330 | sys.executable, '-c', |
| 331 | 'import sysconfig; print(sysconfig.get_platform())', |
| 332 | ], |
| 333 | stdout=subprocess.PIPE, |
| 334 | stderr=dev_null, |
| 335 | env=env) |
| 336 | test_platform = p.communicate()[0].strip() |
| 337 | test_platform = test_platform.decode('utf-8') |
| 338 | status = p.wait() |
Ronald Oussoren | 222e89a | 2011-05-15 16:46:11 +0200 | [diff] [blame] | 339 | |
Brett Cannon | a426554 | 2011-08-04 21:34:52 -0700 | [diff] [blame] | 340 | self.assertEqual(status, 0) |
| 341 | self.assertEqual(my_platform, test_platform) |
Ronald Oussoren | 222e89a | 2011-05-15 16:46:11 +0200 | [diff] [blame] | 342 | |
Richard Oudkerk | 46874ad | 2012-07-27 12:06:55 +0100 | [diff] [blame] | 343 | def test_srcdir(self): |
| 344 | # See Issues #15322, #15364. |
| 345 | srcdir = sysconfig.get_config_var('srcdir') |
| 346 | |
| 347 | self.assertTrue(os.path.isabs(srcdir), srcdir) |
| 348 | self.assertTrue(os.path.isdir(srcdir), srcdir) |
| 349 | |
| 350 | if sysconfig._PYTHON_BUILD: |
| 351 | # The python executable has not been installed so srcdir |
| 352 | # should be a full source checkout. |
| 353 | Python_h = os.path.join(srcdir, 'Include', 'Python.h') |
| 354 | self.assertTrue(os.path.exists(Python_h), Python_h) |
| 355 | self.assertTrue(sysconfig._is_python_source_dir(srcdir)) |
| 356 | elif os.name == 'posix': |
Antoine Pitrou | dde25c4 | 2013-10-23 19:07:40 +0200 | [diff] [blame] | 357 | makefile_dir = os.path.dirname(sysconfig.get_makefile_filename()) |
| 358 | # Issue #19340: srcdir has been realpath'ed already |
| 359 | makefile_dir = os.path.realpath(makefile_dir) |
| 360 | self.assertEqual(makefile_dir, srcdir) |
Richard Oudkerk | 46874ad | 2012-07-27 12:06:55 +0100 | [diff] [blame] | 361 | |
| 362 | def test_srcdir_independent_of_cwd(self): |
| 363 | # srcdir should be independent of the current working directory |
| 364 | # See Issues #15322, #15364. |
| 365 | srcdir = sysconfig.get_config_var('srcdir') |
| 366 | cwd = os.getcwd() |
| 367 | try: |
| 368 | os.chdir('..') |
| 369 | srcdir2 = sysconfig.get_config_var('srcdir') |
| 370 | finally: |
| 371 | os.chdir(cwd) |
| 372 | self.assertEqual(srcdir, srcdir2) |
| 373 | |
Ronald Oussoren | 222e89a | 2011-05-15 16:46:11 +0200 | [diff] [blame] | 374 | |
Victor Stinner | 1273b7c | 2011-05-24 23:37:07 +0200 | [diff] [blame] | 375 | class MakefileTests(unittest.TestCase): |
Éric Araujo | f46676d | 2011-05-26 16:35:14 +0200 | [diff] [blame] | 376 | |
Victor Stinner | 1273b7c | 2011-05-24 23:37:07 +0200 | [diff] [blame] | 377 | @unittest.skipIf(sys.platform.startswith('win'), |
| 378 | 'Test is not Windows compatible') |
| 379 | def test_get_makefile_filename(self): |
| 380 | makefile = sysconfig.get_makefile_filename() |
| 381 | self.assertTrue(os.path.isfile(makefile), makefile) |
| 382 | |
| 383 | def test_parse_makefile(self): |
| 384 | self.addCleanup(unlink, TESTFN) |
| 385 | with open(TESTFN, "w") as makefile: |
| 386 | print("var1=a$(VAR2)", file=makefile) |
| 387 | print("VAR2=b$(var3)", file=makefile) |
| 388 | print("var3=42", file=makefile) |
| 389 | print("var4=$/invalid", file=makefile) |
| 390 | print("var5=dollar$$5", file=makefile) |
| 391 | vars = sysconfig._parse_makefile(TESTFN) |
| 392 | self.assertEqual(vars, { |
| 393 | 'var1': 'ab42', |
| 394 | 'VAR2': 'b42', |
| 395 | 'var3': 42, |
| 396 | 'var4': '$/invalid', |
| 397 | 'var5': 'dollar$5', |
| 398 | }) |
Ronald Oussoren | 222e89a | 2011-05-15 16:46:11 +0200 | [diff] [blame] | 399 | |
| 400 | |
Tarek Ziadé | edacea3 | 2010-01-29 11:41:03 +0000 | [diff] [blame] | 401 | def test_main(): |
Victor Stinner | 1273b7c | 2011-05-24 23:37:07 +0200 | [diff] [blame] | 402 | run_unittest(TestSysConfig, MakefileTests) |
Tarek Ziadé | edacea3 | 2010-01-29 11:41:03 +0000 | [diff] [blame] | 403 | |
| 404 | if __name__ == "__main__": |
| 405 | test_main() |