Skip to content

Commit e0c4437

Browse files
authored
Add support.MS_WINDOWS constant (#110446)
1 parent 3c0f65e commit e0c4437

File tree

15 files changed

+22
-33
lines changed

15 files changed

+22
-33
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/libregrtest/logger.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import time
33

4+
from test.support import MS_WINDOWS
45
from .results import TestResults
56
from .runtests import RunTests
6-
from .utils import print_warning, MS_WINDOWS
7+
from .utils import print_warning
78

89
if MS_WINDOWS:
910
from .win_utils import WindowsLoadTracker

Lib/test/libregrtest/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import time
88

99
from test import support
10-
from test.support import os_helper
10+
from test.support import os_helper, MS_WINDOWS
1111

1212
from .cmdline import _parse_args, Namespace
1313
from .findtests import findtests, split_test_packages, list_cases
@@ -24,7 +24,7 @@
2424
printlist, get_temp_dir, get_work_dir, exit_timeout,
2525
display_header, cleanup_temp_dir, print_warning,
2626
is_cross_compiled, get_host_runner,
27-
MS_WINDOWS, EXIT_TIMEOUT)
27+
EXIT_TIMEOUT)
2828

2929

3030
class Regrtest:

Lib/test/libregrtest/run_workers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
from typing import Literal, TextIO
1414

1515
from test import support
16-
from test.support import os_helper
16+
from test.support import os_helper, MS_WINDOWS
1717

1818
from .logger import Logger
1919
from .result import TestResult, State
2020
from .results import TestResults
2121
from .runtests import RunTests, JsonFile, JsonFileType
2222
from .single import PROGRESS_MIN_TIME
2323
from .utils import (
24-
StrPath, TestName, MS_WINDOWS,
24+
StrPath, TestName,
2525
format_duration, print_warning, count, plural, get_signal_name)
2626
from .worker import create_worker_process, USE_PROCESS_GROUP
2727

Lib/test/libregrtest/utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from test.support import threading_helper
2020

2121

22-
MS_WINDOWS = (sys.platform == 'win32')
23-
2422
# All temporary files and temporary directories created by libregrtest should
2523
# use TMP_PREFIX so cleanup_temp_dir() can remove them all.
2624
TMP_PREFIX = 'test_python_'

Lib/test/pythoninfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ def collect_support(info_add):
730730
return
731731

732732
attributes = (
733+
'MS_WINDOWS',
733734
'has_fork_support',
734735
'has_socket_support',
735736
'has_strftime_extensions',

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 has_no_debug_ranges():
509509
def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
510510
return unittest.skipIf(has_no_debug_ranges(), reason)
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
@@ -9,7 +9,6 @@
99
from test import support
1010

1111

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

@@ -30,7 +29,7 @@ def test_build_cpp03(self):
3029

3130
# With MSVC, the linker fails with: cannot open file 'python311.lib'
3231
# https://github.com/python/cpython/pull/32175#issuecomment-1111175897
33-
@unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
32+
@unittest.skipIf(support.MS_WINDOWS, 'test fails on Windows')
3433
# Building and running an extension in clang sanitizing mode is not
3534
# straightforward
3635
@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
@@ -348,7 +345,7 @@ def test_simple_initialization_api(self):
348345
out, err = self.run_embedded_interpreter("test_repeated_simple_init")
349346
self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
350347

351-
@requires_specialization
348+
@support.requires_specialization
352349
def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
353350
# https://github.com/python/cpython/issues/92031
354351

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
import tempfile
1312
import unittest
1413
from textwrap import dedent
@@ -22,7 +21,6 @@
2221
raise unittest.SkipTest("test module requires subprocess")
2322

2423
TIMEOUT = 0.5
25-
MS_WINDOWS = (os.name == 'nt')
2624

2725

2826
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_regrtest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
EXITCODE_RERUN_FAIL = 5
4343
EXITCODE_INTERRUPTED = 130
4444

45-
MS_WINDOWS = (sys.platform == 'win32')
46-
4745
TEST_INTERRUPTED = textwrap.dedent("""
4846
from signal import SIGINT, raise_signal
4947
try:
@@ -2072,7 +2070,7 @@ def test_crash(self):
20722070
self.check_executed_tests(output, testname,
20732071
failed=[testname],
20742072
stats=0, parallel=True)
2075-
if not MS_WINDOWS:
2073+
if not support.MS_WINDOWS:
20762074
exitcode = -int(signal.SIGSEGV)
20772075
self.assertIn(f"Exit code {exitcode} (SIGSEGV)", output)
20782076
self.check_line(output, "just before crash!", full=True, regex=False)

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)