Skip to content

Commit 88223f1

Browse files
authored
[3.11] Add support.MS_WINDOWS constant (#110446) (#110452) (#110464)
[3.12] Add support.MS_WINDOWS constant (#110446) (#110452) Add support.MS_WINDOWS constant (#110446) (cherry picked from commit e0c4437) (cherry picked from commit e188534)
1 parent 4499e6c commit 88223f1

File tree

10 files changed

+27
-22
lines changed

10 files changed

+27
-22
lines changed

Lib/test/_test_embed_set_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import os
1010
import sys
1111
import unittest
12+
from test.support import MS_WINDOWS
1213

1314

14-
MS_WINDOWS = (os.name == 'nt')
1515
MAX_HASH_SEED = 4294967295
1616

1717
class SetConfigTests(unittest.TestCase):

Lib/test/pythoninfo.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,19 @@ def collect_test_support(info_add):
713713
attributes = ('IPV6_ENABLED',)
714714
copy_attributes(info_add, support, 'test_support.%s', attributes)
715715

716+
attributes = (
717+
'MS_WINDOWS',
718+
'has_fork_support',
719+
'has_socket_support',
720+
'has_strftime_extensions',
721+
'has_subprocess_support',
722+
'is_android',
723+
'is_emscripten',
724+
'is_jython',
725+
'is_wasi',
726+
)
727+
copy_attributes(info_add, support, 'support.%s', attributes)
728+
716729
call_func(info_add, 'test_support._is_gui_available', support, '_is_gui_available')
717730
call_func(info_add, 'test_support.python_is_optimized', support, 'python_is_optimized')
718731

Lib/test/support/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"check__all__", "skip_if_buggy_ucrt_strfptime",
4949
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
5050
# sys
51-
"is_jython", "is_android", "is_emscripten", "is_wasi",
51+
"MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
5252
"check_impl_detail", "unix_shell", "setswitchinterval",
5353
# network
5454
"open_urlresource",
@@ -501,6 +501,8 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
501501
requires_legacy_unicode_capi = unittest.skipUnless(unicode_legacy_string,
502502
'requires legacy Unicode C API')
503503

504+
MS_WINDOWS = (sys.platform == 'win32')
505+
504506
is_jython = sys.platform.startswith('java')
505507

506508
is_android = hasattr(sys, 'getandroidapilevel')

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
from test.support import os_helper
1616

1717

18-
MS_WINDOWS = (sys.platform == 'win32')
19-
if MS_WINDOWS:
18+
if support.MS_WINDOWS:
2019
import msvcrt
2120
else:
2221
from asyncio import unix_events
@@ -266,7 +265,7 @@ def test_stdin_broken_pipe(self):
266265
rfd, wfd = os.pipe()
267266
self.addCleanup(os.close, rfd)
268267
self.addCleanup(os.close, wfd)
269-
if MS_WINDOWS:
268+
if support.MS_WINDOWS:
270269
handle = msvcrt.get_osfhandle(rfd)
271270
os.set_handle_inheritable(handle, True)
272271
code = textwrap.dedent(f'''

Lib/test/test_cppext/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test.support import os_helper
1010

1111

12-
MS_WINDOWS = (sys.platform == 'win32')
1312
SETUP = os.path.join(os.path.dirname(__file__), 'setup.py')
1413

1514

@@ -25,7 +24,7 @@ def test_build_cpp03(self):
2524

2625
# With MSVC, the linker fails with: cannot open file 'python311.lib'
2726
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
28-
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
27+
@unittest.skipIf(support.MS_WINDOWS, 'test fails on Windows')
2928
# Building and running an extension in clang sanitizing mode is not
3029
# straightforward
3130
@unittest.skipIf(
@@ -53,7 +52,7 @@ def _check_build(self, std_cpp03, extension_name):
5352
python_exe = 'python'
5453
if sys.executable.endswith('.exe'):
5554
python_exe += '.exe'
56-
if MS_WINDOWS:
55+
if support.MS_WINDOWS:
5756
python = os.path.join(venv_dir, 'Scripts', python_exe)
5857
else:
5958
python = os.path.join(venv_dir, 'bin', python_exe)

Lib/test/test_cppext/setup.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
import shlex
55
import sys
66
import sysconfig
7+
from test import support
78

89
from setuptools import setup, Extension
910

1011

11-
MS_WINDOWS = (sys.platform == 'win32')
12-
13-
1412
SOURCE = os.path.join(os.path.dirname(__file__), 'extension.cpp')
15-
if not MS_WINDOWS:
13+
if not support.MS_WINDOWS:
1614
# C++ compiler flags for GCC and clang
1715
CPPFLAGS = [
1816
# gh-91321: The purpose of _testcppext extension is to check that building

Lib/test/test_embed.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
22
from test import support
3-
from test.support import import_helper
4-
from test.support import os_helper
3+
from test.support import import_helper, os_helper, MS_WINDOWS
54
import unittest
65

76
from collections import namedtuple
@@ -20,7 +19,6 @@
2019
if not support.has_subprocess_support:
2120
raise unittest.SkipTest("test module requires subprocess")
2221

23-
MS_WINDOWS = (os.name == 'nt')
2422
MACOS = (sys.platform == 'darwin')
2523
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
2624
PYMEM_ALLOCATOR_NOT_SET = 0

Lib/test/test_faulthandler.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import subprocess
88
import sys
99
from test import support
10-
from test.support import os_helper
11-
from test.support import script_helper, is_android
10+
from test.support import os_helper, script_helper, is_android, MS_WINDOWS
1211
from test.support import skip_if_sanitizer
1312
import tempfile
1413
import unittest
@@ -23,7 +22,6 @@
2322
raise unittest.SkipTest("test module requires subprocess")
2423

2524
TIMEOUT = 0.5
26-
MS_WINDOWS = (os.name == 'nt')
2725

2826

2927
def expected_traceback(lineno1, lineno2, header, min_count=1):

Lib/test/test_gdb/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
from test import support
1010

1111

12-
MS_WINDOWS = (os.name == 'nt')
13-
if MS_WINDOWS:
12+
if support.MS_WINDOWS:
1413
# On Windows, Python is usually built by MSVC. Passing /p:DebugSymbols=true
1514
# option to MSBuild produces PDB debug symbols, but gdb doesn't support PDB
1615
# debug symbol files.

Lib/test/test_utf8_mode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
import unittest
1010
from test import support
1111
from test.support.script_helper import assert_python_ok, assert_python_failure
12-
from test.support import os_helper
12+
from test.support import os_helper, MS_WINDOWS
1313

1414

15-
MS_WINDOWS = (sys.platform == 'win32')
1615
POSIX_LOCALES = ('C', 'POSIX')
1716
VXWORKS = (sys.platform == "vxworks")
1817

0 commit comments

Comments
 (0)