Skip to content

Commit e188534

Browse files
authored
[3.12] Add support.MS_WINDOWS constant (#110446) (#110452)
Add support.MS_WINDOWS constant (#110446) (cherry picked from commit e0c4437)
1 parent 67028f0 commit e188534

File tree

10 files changed

+27
-23
lines changed

10 files changed

+27
-23
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
@@ -704,6 +704,19 @@ def collect_test_support(info_add):
704704
attributes = ('IPV6_ENABLED',)
705705
copy_attributes(info_add, support, 'test_support.%s', attributes)
706706

707+
attributes = (
708+
'MS_WINDOWS',
709+
'has_fork_support',
710+
'has_socket_support',
711+
'has_strftime_extensions',
712+
'has_subprocess_support',
713+
'is_android',
714+
'is_emscripten',
715+
'is_jython',
716+
'is_wasi',
717+
)
718+
copy_attributes(info_add, support, 'support.%s', attributes)
719+
707720
call_func(info_add, 'test_support._is_gui_available', support, '_is_gui_available')
708721
call_func(info_add, 'test_support.python_is_optimized', support, 'python_is_optimized')
709722

Lib/test/support/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
4747
"requires_limited_api", "requires_specialization",
4848
# sys
49-
"is_jython", "is_android", "is_emscripten", "is_wasi",
49+
"MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
5050
"check_impl_detail", "unix_shell", "setswitchinterval",
5151
# os
5252
"get_pagesize",
@@ -509,6 +509,8 @@ def requires_legacy_unicode_capi():
509509
return unittest.skipUnless(unicode_legacy_string,
510510
'requires legacy Unicode C API')
511511

512+
MS_WINDOWS = (sys.platform == 'win32')
513+
512514
# Is not actually used in tests, but is kept for compatibility.
513515
is_jython = sys.platform.startswith('java')
514516

Lib/test/test_asyncio/test_subprocess.py

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

1616

17-
MS_WINDOWS = (sys.platform == 'win32')
18-
if MS_WINDOWS:
17+
if support.MS_WINDOWS:
1918
import msvcrt
2019
else:
2120
from asyncio import unix_events
@@ -283,7 +282,7 @@ def test_stdin_broken_pipe(self):
283282
rfd, wfd = os.pipe()
284283
self.addCleanup(os.close, rfd)
285284
self.addCleanup(os.close, wfd)
286-
if MS_WINDOWS:
285+
if support.MS_WINDOWS:
287286
handle = msvcrt.get_osfhandle(rfd)
288287
os.set_handle_inheritable(handle, True)
289288
code = textwrap.dedent(f'''

Lib/test/test_cppext/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from test.support import os_helper
1111

1212

13-
MS_WINDOWS = (sys.platform == 'win32')
1413
SOURCE = os.path.join(os.path.dirname(__file__), 'extension.cpp')
1514
SETUP = os.path.join(os.path.dirname(__file__), 'setup.py')
1615

@@ -27,7 +26,7 @@ def test_build_cpp03(self):
2726

2827
# With MSVC, the linker fails with: cannot open file 'python311.lib'
2928
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
30-
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
29+
@unittest.skipIf(support.MS_WINDOWS, 'test fails on Windows')
3130
# Building and running an extension in clang sanitizing mode is not
3231
# straightforward
3332
@unittest.skipIf(

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 = '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: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +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
5-
from test.support import requires_specialization
3+
from test.support import import_helper, os_helper, MS_WINDOWS
64
import unittest
75

86
from collections import namedtuple
@@ -21,7 +19,6 @@
2119
if not support.has_subprocess_support:
2220
raise unittest.SkipTest("test module requires subprocess")
2321

24-
MS_WINDOWS = (os.name == 'nt')
2522
MACOS = (sys.platform == 'darwin')
2623
PYMEM_ALLOCATOR_NOT_SET = 0
2724
PYMEM_ALLOCATOR_DEBUG = 2
@@ -347,7 +344,7 @@ def test_simple_initialization_api(self):
347344
out, err = self.run_embedded_interpreter("test_repeated_simple_init")
348345
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
349346

350-
@requires_specialization
347+
@support.requires_specialization
351348
def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
352349
# https://github.com/python/cpython/issues/92031
353350

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)