|
9 | 9 |
|
10 | 10 | from __future__ import annotations |
11 | 11 |
|
12 | | -import os |
13 | 12 | from unittest.mock import MagicMock, patch |
14 | 13 |
|
15 | 14 |
|
@@ -129,108 +128,51 @@ def test_windows_detection_fallback_on_exception( |
129 | 128 | assert result["release"] == "10" |
130 | 129 | assert result["machine"] == "AMD64" |
131 | 130 |
|
132 | | - @patch("winml.modelkit.commands.sys.OS") |
133 | | - @patch("winml.modelkit.commands.sys.platform") |
134 | | - def test_processor_unknown_fallback( |
135 | | - self, mock_platform: MagicMock, mock_os_class: MagicMock |
136 | | - ) -> None: |
137 | | - """Test processor defaults to 'Unknown' when empty.""" |
138 | | - from winml.modelkit.commands.sys import _get_platform_info |
139 | | - |
140 | | - mock_platform.system.return_value = "Windows" |
141 | | - mock_platform.release.return_value = "10" |
142 | | - mock_platform.machine.return_value = "AMD64" |
143 | | - mock_platform.processor.return_value = "" # Empty string |
144 | | - |
145 | | - mock_os_instance = MagicMock() |
146 | | - mock_os_instance.is_windows_11.return_value = False |
147 | | - mock_os_class.get.return_value = mock_os_instance |
148 | | - |
149 | | - with patch.dict(os.environ, {"PROCESSOR_ARCHITECTURE": "AMD64"}, clear=True): |
150 | | - result = _get_platform_info() |
151 | | - |
152 | | - assert result["processor"] == "Unknown" |
153 | | - |
154 | | - |
155 | | -class TestWindowsHostArchitecture: |
156 | | - """Test that Windows machine architecture reports the host, not the Python process arch. |
157 | | -
|
158 | | - Regression coverage for https://github.com/microsoft/WinML-ModelKit/issues/58: |
159 | | - `platform.machine()` returns the running Python process architecture, which is |
160 | | - incorrect on ARM64 Windows when an x64 Python runs under WOW64 emulation. |
161 | | - """ |
162 | | - |
163 | | - @patch("winml.modelkit.commands.sys.OS") |
164 | 131 | @patch("winml.modelkit.commands.sys.platform") |
165 | | - def test_native_arm64_python_reports_arm64( |
166 | | - self, mock_platform: MagicMock, mock_os_class: MagicMock |
167 | | - ) -> None: |
168 | | - """Native ARM64 Python on ARM64 Windows must report ARM64.""" |
| 132 | + def test_non_windows_platform(self, mock_platform: MagicMock) -> None: |
| 133 | + """Test non-Windows platforms pass through unchanged.""" |
169 | 134 | from winml.modelkit.commands.sys import _get_platform_info |
170 | 135 |
|
171 | | - mock_platform.system.return_value = "Windows" |
172 | | - mock_platform.release.return_value = "10" |
173 | | - mock_platform.machine.return_value = "ARM64" |
174 | | - mock_platform.processor.return_value = "ARMv8 (64-bit)" |
175 | | - |
176 | | - mock_os_instance = MagicMock() |
177 | | - mock_os_instance.is_windows_11.return_value = True |
178 | | - mock_os_class.get.return_value = mock_os_instance |
| 136 | + # Setup mocks for Linux |
| 137 | + mock_platform.system.return_value = "Linux" |
| 138 | + mock_platform.release.return_value = "5.15.0" |
| 139 | + mock_platform.machine.return_value = "x86_64" |
| 140 | + mock_platform.processor.return_value = "x86_64" |
179 | 141 |
|
180 | | - with patch.dict(os.environ, {"PROCESSOR_ARCHITECTURE": "ARM64"}, clear=True): |
181 | | - result = _get_platform_info() |
| 142 | + result = _get_platform_info() |
182 | 143 |
|
183 | | - assert result["machine"] == "ARM64" |
| 144 | + assert result["system"] == "Linux" |
| 145 | + assert result["release"] == "5.15.0" |
| 146 | + assert result["machine"] == "x86_64" |
184 | 147 |
|
185 | | - @patch("winml.modelkit.commands.sys.OS") |
186 | 148 | @patch("winml.modelkit.commands.sys.platform") |
187 | | - def test_x64_emulated_python_on_arm64_reports_arm64( |
188 | | - self, mock_platform: MagicMock, mock_os_class: MagicMock |
189 | | - ) -> None: |
190 | | - """x64-emulated Python on ARM64 Windows must report ARM64, not AMD64. |
191 | | -
|
192 | | - Under WOW64 emulation, PROCESSOR_ARCHITECTURE reflects the emulated |
193 | | - process arch (AMD64) and PROCESSOR_ARCHITEW6432 holds the true host |
194 | | - arch (ARM64). The host arch is what users want to see. |
195 | | - """ |
| 149 | + def test_macos_platform(self, mock_platform: MagicMock) -> None: |
| 150 | + """Test macOS platforms pass through unchanged.""" |
196 | 151 | from winml.modelkit.commands.sys import _get_platform_info |
197 | 152 |
|
198 | | - mock_platform.system.return_value = "Windows" |
199 | | - mock_platform.release.return_value = "11" |
200 | | - mock_platform.machine.return_value = "AMD64" |
201 | | - mock_platform.processor.return_value = "Intel64 Family 6" |
| 153 | + # Setup mocks for macOS |
| 154 | + mock_platform.system.return_value = "Darwin" |
| 155 | + mock_platform.release.return_value = "21.6.0" |
| 156 | + mock_platform.machine.return_value = "arm64" |
| 157 | + mock_platform.processor.return_value = "arm" |
202 | 158 |
|
203 | | - mock_os_instance = MagicMock() |
204 | | - mock_os_instance.is_windows_11.return_value = True |
205 | | - mock_os_class.get.return_value = mock_os_instance |
206 | | - |
207 | | - with patch.dict( |
208 | | - os.environ, |
209 | | - {"PROCESSOR_ARCHITECTURE": "AMD64", "PROCESSOR_ARCHITEW6432": "ARM64"}, |
210 | | - clear=True, |
211 | | - ): |
212 | | - result = _get_platform_info() |
| 159 | + result = _get_platform_info() |
213 | 160 |
|
214 | | - assert result["machine"] == "ARM64" |
| 161 | + assert result["system"] == "Darwin" |
| 162 | + assert result["release"] == "21.6.0" |
| 163 | + assert result["machine"] == "arm64" |
215 | 164 |
|
216 | | - @patch("winml.modelkit.commands.sys.OS") |
217 | 165 | @patch("winml.modelkit.commands.sys.platform") |
218 | | - def test_native_amd64_python_reports_amd64( |
219 | | - self, mock_platform: MagicMock, mock_os_class: MagicMock |
220 | | - ) -> None: |
221 | | - """Native AMD64 Python on AMD64 Windows must still report AMD64.""" |
| 166 | + def test_processor_unknown_fallback(self, mock_platform: MagicMock) -> None: |
| 167 | + """Test processor defaults to 'Unknown' when empty.""" |
222 | 168 | from winml.modelkit.commands.sys import _get_platform_info |
223 | 169 |
|
224 | | - mock_platform.system.return_value = "Windows" |
225 | | - mock_platform.release.return_value = "11" |
226 | | - mock_platform.machine.return_value = "AMD64" |
227 | | - mock_platform.processor.return_value = "Intel64 Family 6" |
228 | | - |
229 | | - mock_os_instance = MagicMock() |
230 | | - mock_os_instance.is_windows_11.return_value = True |
231 | | - mock_os_class.get.return_value = mock_os_instance |
| 170 | + # Setup mocks |
| 171 | + mock_platform.system.return_value = "Linux" |
| 172 | + mock_platform.release.return_value = "5.15.0" |
| 173 | + mock_platform.machine.return_value = "x86_64" |
| 174 | + mock_platform.processor.return_value = "" # Empty string |
232 | 175 |
|
233 | | - with patch.dict(os.environ, {"PROCESSOR_ARCHITECTURE": "AMD64"}, clear=True): |
234 | | - result = _get_platform_info() |
| 176 | + result = _get_platform_info() |
235 | 177 |
|
236 | | - assert result["machine"] == "AMD64" |
| 178 | + assert result["processor"] == "Unknown" |
0 commit comments