|
2 | 2 | import os
|
3 | 3 | import sys
|
4 | 4 | import unittest
|
| 5 | +import sysconfig as stdlib_sysconfig |
5 | 6 | from copy import copy
|
6 | 7 | from test.support import run_unittest
|
7 | 8 | from unittest import mock
|
|
10 | 11 | from distutils.util import (get_platform, convert_path, change_root,
|
11 | 12 | check_environ, split_quoted, strtobool,
|
12 | 13 | rfc822_escape, byte_compile,
|
13 |
| - grok_environment_error) |
| 14 | + grok_environment_error, get_host_platform) |
14 | 15 | from distutils import util # used to patch _environ_checked
|
15 |
| -from distutils.sysconfig import get_config_vars |
16 | 16 | from distutils import sysconfig
|
17 | 17 | from distutils.tests import support
|
18 |
| -import _osx_support |
19 | 18 |
|
20 | 19 | class UtilTestCase(support.EnvironGuard, unittest.TestCase):
|
21 | 20 |
|
@@ -63,110 +62,26 @@ def _set_uname(self, uname):
|
63 | 62 | def _get_uname(self):
|
64 | 63 | return self._uname
|
65 | 64 |
|
66 |
| - def test_get_platform(self): |
67 |
| - |
68 |
| - # windows XP, 32bits |
69 |
| - os.name = 'nt' |
70 |
| - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' |
71 |
| - '[MSC v.1310 32 bit (Intel)]') |
72 |
| - sys.platform = 'win32' |
73 |
| - self.assertEqual(get_platform(), 'win32') |
74 |
| - |
75 |
| - # windows XP, amd64 |
76 |
| - os.name = 'nt' |
77 |
| - sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) ' |
78 |
| - '[MSC v.1310 32 bit (Amd64)]') |
79 |
| - sys.platform = 'win32' |
80 |
| - self.assertEqual(get_platform(), 'win-amd64') |
81 |
| - |
82 |
| - # macbook |
83 |
| - os.name = 'posix' |
84 |
| - sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) ' |
85 |
| - '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]') |
86 |
| - sys.platform = 'darwin' |
87 |
| - self._set_uname(('Darwin', 'macziade', '8.11.1', |
88 |
| - ('Darwin Kernel Version 8.11.1: ' |
89 |
| - 'Wed Oct 10 18:23:28 PDT 2007; ' |
90 |
| - 'root:xnu-792.25.20~1/RELEASE_I386'), 'i386')) |
91 |
| - _osx_support._remove_original_values(get_config_vars()) |
92 |
| - get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.3' |
93 |
| - |
94 |
| - get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g ' |
95 |
| - '-fwrapv -O3 -Wall -Wstrict-prototypes') |
96 |
| - |
97 |
| - cursize = sys.maxsize |
98 |
| - sys.maxsize = (2 ** 31)-1 |
99 |
| - try: |
100 |
| - self.assertEqual(get_platform(), 'macosx-10.3-i386') |
101 |
| - finally: |
102 |
| - sys.maxsize = cursize |
103 |
| - |
104 |
| - # macbook with fat binaries (fat, universal or fat64) |
105 |
| - _osx_support._remove_original_values(get_config_vars()) |
106 |
| - get_config_vars()['MACOSX_DEPLOYMENT_TARGET'] = '10.4' |
107 |
| - get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot ' |
108 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
109 |
| - '-fno-strict-aliasing -fno-common ' |
110 |
| - '-dynamic -DNDEBUG -g -O3') |
111 |
| - |
112 |
| - self.assertEqual(get_platform(), 'macosx-10.4-fat') |
113 |
| - |
114 |
| - _osx_support._remove_original_values(get_config_vars()) |
115 |
| - os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.1' |
116 |
| - self.assertEqual(get_platform(), 'macosx-10.4-fat') |
117 |
| - |
| 65 | + def test_get_host_platform(self): |
| 66 | + with unittest.mock.patch('os.name', 'nt'): |
| 67 | + with unittest.mock.patch('sys.version', '... [... (ARM64)]'): |
| 68 | + self.assertEqual(get_host_platform(), 'win-arm64') |
| 69 | + with unittest.mock.patch('sys.version', '... [... (ARM)]'): |
| 70 | + self.assertEqual(get_host_platform(), 'win-arm32') |
118 | 71 |
|
119 |
| - _osx_support._remove_original_values(get_config_vars()) |
120 |
| - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot ' |
121 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
122 |
| - '-fno-strict-aliasing -fno-common ' |
123 |
| - '-dynamic -DNDEBUG -g -O3') |
| 72 | + with unittest.mock.patch('sys.version_info', (3, 9, 0, 'final', 0)): |
| 73 | + self.assertEqual(get_host_platform(), stdlib_sysconfig.get_platform()) |
124 | 74 |
|
125 |
| - self.assertEqual(get_platform(), 'macosx-10.4-intel') |
126 |
| - |
127 |
| - _osx_support._remove_original_values(get_config_vars()) |
128 |
| - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot ' |
129 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
130 |
| - '-fno-strict-aliasing -fno-common ' |
131 |
| - '-dynamic -DNDEBUG -g -O3') |
132 |
| - self.assertEqual(get_platform(), 'macosx-10.4-fat3') |
133 |
| - |
134 |
| - _osx_support._remove_original_values(get_config_vars()) |
135 |
| - get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot ' |
136 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
137 |
| - '-fno-strict-aliasing -fno-common ' |
138 |
| - '-dynamic -DNDEBUG -g -O3') |
139 |
| - self.assertEqual(get_platform(), 'macosx-10.4-universal') |
140 |
| - |
141 |
| - _osx_support._remove_original_values(get_config_vars()) |
142 |
| - get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot ' |
143 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
144 |
| - '-fno-strict-aliasing -fno-common ' |
145 |
| - '-dynamic -DNDEBUG -g -O3') |
146 |
| - |
147 |
| - self.assertEqual(get_platform(), 'macosx-10.4-fat64') |
148 |
| - |
149 |
| - for arch in ('ppc', 'i386', 'x86_64', 'ppc64'): |
150 |
| - _osx_support._remove_original_values(get_config_vars()) |
151 |
| - get_config_vars()['CFLAGS'] = ('-arch %s -isysroot ' |
152 |
| - '/Developer/SDKs/MacOSX10.4u.sdk ' |
153 |
| - '-fno-strict-aliasing -fno-common ' |
154 |
| - '-dynamic -DNDEBUG -g -O3'%(arch,)) |
155 |
| - |
156 |
| - self.assertEqual(get_platform(), 'macosx-10.4-%s'%(arch,)) |
157 |
| - |
158 |
| - |
159 |
| - # linux debian sarge |
160 |
| - os.name = 'posix' |
161 |
| - sys.version = ('2.3.5 (#1, Jul 4 2007, 17:28:59) ' |
162 |
| - '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]') |
163 |
| - sys.platform = 'linux2' |
164 |
| - self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7', |
165 |
| - '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686')) |
166 |
| - |
167 |
| - self.assertEqual(get_platform(), 'linux-i686') |
168 |
| - |
169 |
| - # XXX more platforms to tests here |
| 75 | + def test_get_platform(self): |
| 76 | + with unittest.mock.patch('os.name', 'nt'): |
| 77 | + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x86'}): |
| 78 | + self.assertEqual(get_platform(), 'win32') |
| 79 | + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'x64'}): |
| 80 | + self.assertEqual(get_platform(), 'win-amd64') |
| 81 | + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm'}): |
| 82 | + self.assertEqual(get_platform(), 'win-arm32') |
| 83 | + with unittest.mock.patch.dict('os.environ', {'VSCMD_ARG_TGT_ARCH': 'arm64'}): |
| 84 | + self.assertEqual(get_platform(), 'win-arm64') |
170 | 85 |
|
171 | 86 | def test_convert_path(self):
|
172 | 87 | # linux/mac
|
|
0 commit comments