]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add support.MS_WINDOWS constant (#110446)
authorVictor Stinner <vstinner@python.org>
Fri, 6 Oct 2023 00:37:28 +0000 (02:37 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Oct 2023 00:37:28 +0000 (02:37 +0200)
15 files changed:
Lib/test/_test_embed_set_config.py
Lib/test/libregrtest/logger.py
Lib/test/libregrtest/main.py
Lib/test/libregrtest/run_workers.py
Lib/test/libregrtest/utils.py
Lib/test/pythoninfo.py
Lib/test/support/__init__.py
Lib/test/test_asyncio/test_subprocess.py
Lib/test/test_cppext/__init__.py
Lib/test/test_cppext/setup.py
Lib/test/test_embed.py
Lib/test/test_faulthandler.py
Lib/test/test_gdb/__init__.py
Lib/test/test_regrtest.py
Lib/test/test_utf8_mode.py

index 0c016b5d75d7342efd2abf5ac7e61bf64f3ca9c9..a2ddd133cf47c87b5cb464ec6f8b275e9f72b85c 100644 (file)
@@ -9,9 +9,9 @@ import _testinternalcapi
 import os
 import sys
 import unittest
+from test.support import MS_WINDOWS
 
 
-MS_WINDOWS = (os.name == 'nt')
 MAX_HASH_SEED = 4294967295
 
 class SetConfigTests(unittest.TestCase):
index 2f0c4bf1c84b5cd186b753236130123c4bb6c184..a125706927393c5b46553e8e9bd46d143c6f5cae 100644 (file)
@@ -1,9 +1,10 @@
 import os
 import time
 
+from test.support import MS_WINDOWS
 from .results import TestResults
 from .runtests import RunTests
-from .utils import print_warning, MS_WINDOWS
+from .utils import print_warning
 
 if MS_WINDOWS:
     from .win_utils import WindowsLoadTracker
index 60179ec7708c1cf51340b6ac6a2c5cf0483c1162..cb60d5af732b437e2053c4ebfe60765ac80d6032 100644 (file)
@@ -7,7 +7,7 @@ import sysconfig
 import time
 
 from test import support
-from test.support import os_helper
+from test.support import os_helper, MS_WINDOWS
 
 from .cmdline import _parse_args, Namespace
 from .findtests import findtests, split_test_packages, list_cases
@@ -24,7 +24,7 @@ from .utils import (
     printlist, get_temp_dir, get_work_dir, exit_timeout,
     display_header, cleanup_temp_dir, print_warning,
     is_cross_compiled, get_host_runner,
-    MS_WINDOWS, EXIT_TIMEOUT)
+    EXIT_TIMEOUT)
 
 
 class Regrtest:
index 106f9730832e5437cf84cbdd89460fdabff8248a..16f8331abd32f9d66e8ec346c853066780ddaf23 100644 (file)
@@ -13,7 +13,7 @@ import traceback
 from typing import Literal, TextIO
 
 from test import support
-from test.support import os_helper
+from test.support import os_helper, MS_WINDOWS
 
 from .logger import Logger
 from .result import TestResult, State
@@ -21,7 +21,7 @@ from .results import TestResults
 from .runtests import RunTests, JsonFile, JsonFileType
 from .single import PROGRESS_MIN_TIME
 from .utils import (
-    StrPath, TestName, MS_WINDOWS,
+    StrPath, TestName,
     format_duration, print_warning, count, plural, get_signal_name)
 from .worker import create_worker_process, USE_PROCESS_GROUP
 
index ea2086cd71b173db76b6553ea5a3fe89fb731456..aac8395da87845b8cb38621ff04495f428b49e9c 100644 (file)
@@ -19,8 +19,6 @@ from test.support import os_helper
 from test.support import threading_helper
 
 
-MS_WINDOWS = (sys.platform == 'win32')
-
 # All temporary files and temporary directories created by libregrtest should
 # use TMP_PREFIX so cleanup_temp_dir() can remove them all.
 TMP_PREFIX = 'test_python_'
index 58d906ffc62a53375d51af9b801b11c4710e2b6e..4f3ebb12ed957d01ed3a5e56c62e294d0433dbe2 100644 (file)
@@ -730,6 +730,7 @@ def collect_support(info_add):
         return
 
     attributes = (
+        'MS_WINDOWS',
         'has_fork_support',
         'has_socket_support',
         'has_strftime_extensions',
index f3270d66bd085271339f6a8912bfd1c91d2078db..982d0df3b86f483477264df845e2a986fb26561f 100644 (file)
@@ -46,7 +46,7 @@ __all__ = [
     "check_disallow_instantiation", "check_sanitizer", "skip_if_sanitizer",
     "requires_limited_api", "requires_specialization",
     # sys
-    "is_jython", "is_android", "is_emscripten", "is_wasi",
+    "MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
     "check_impl_detail", "unix_shell", "setswitchinterval",
     # os
     "get_pagesize",
@@ -509,6 +509,8 @@ def has_no_debug_ranges():
 def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
     return unittest.skipIf(has_no_debug_ranges(), reason)
 
+MS_WINDOWS = (sys.platform == 'win32')
+
 # Is not actually used in tests, but is kept for compatibility.
 is_jython = sys.platform.startswith('java')
 
index dc5a48d500e8d5961bf127fee1f638c2daa698e4..179c8cb8cc17cf89805443699cf0a349efe7a367 100644 (file)
@@ -14,8 +14,7 @@ from test import support
 from test.support import os_helper
 
 
-MS_WINDOWS = (sys.platform == 'win32')
-if MS_WINDOWS:
+if support.MS_WINDOWS:
     import msvcrt
 else:
     from asyncio import unix_events
@@ -283,7 +282,7 @@ class SubprocessMixin:
         rfd, wfd = os.pipe()
         self.addCleanup(os.close, rfd)
         self.addCleanup(os.close, wfd)
-        if MS_WINDOWS:
+        if support.MS_WINDOWS:
             handle = msvcrt.get_osfhandle(rfd)
             os.set_handle_inheritable(handle, True)
             code = textwrap.dedent(f'''
index 25b6fc64a03a518d5ae4f91cb4fefb881668648e..4d9ee3cb2228aee553e8be0264451f0acaa53258 100644 (file)
@@ -9,7 +9,6 @@ import sysconfig
 from test import support
 
 
-MS_WINDOWS = (sys.platform == 'win32')
 SOURCE = os.path.join(os.path.dirname(__file__), 'extension.cpp')
 SETUP = os.path.join(os.path.dirname(__file__), 'setup.py')
 
@@ -30,7 +29,7 @@ class TestCPPExt(unittest.TestCase):
 
     # With MSVC, the linker fails with: cannot open file 'python311.lib'
     # https://github.com/python/cpython/pull/32175#issuecomment-1111175897
-    @unittest.skipIf(MS_WINDOWS, 'test fails on Windows')
+    @unittest.skipIf(support.MS_WINDOWS, 'test fails on Windows')
     # Building and running an extension in clang sanitizing mode is not
     # straightforward
     @unittest.skipIf(
index 976633bc33889cd824aa01b244d816453cbd55f0..c7ba1efb4dd05a4af3fe6dce221568aa16f115bc 100644 (file)
@@ -4,15 +4,13 @@ import os
 import shlex
 import sys
 import sysconfig
+from test import support
 
 from setuptools import setup, Extension
 
 
-MS_WINDOWS = (sys.platform == 'win32')
-
-
 SOURCE = 'extension.cpp'
-if not MS_WINDOWS:
+if not support.MS_WINDOWS:
     # C++ compiler flags for GCC and clang
     CPPFLAGS = [
         # gh-91321: The purpose of _testcppext extension is to check that building
index 46c9b03c4178e9ce56032d46692da5012d3acfce..06f2d8b9a3621fcfa949efd87b58eed35c62bedb 100644 (file)
@@ -1,8 +1,6 @@
 # Run the tests in Programs/_testembed.c (tests for the CPython embedding APIs)
 from test import support
-from test.support import import_helper
-from test.support import os_helper
-from test.support import requires_specialization
+from test.support import import_helper, os_helper, MS_WINDOWS
 import unittest
 
 from collections import namedtuple
@@ -21,7 +19,6 @@ import textwrap
 if not support.has_subprocess_support:
     raise unittest.SkipTest("test module requires subprocess")
 
-MS_WINDOWS = (os.name == 'nt')
 MACOS = (sys.platform == 'darwin')
 PYMEM_ALLOCATOR_NOT_SET = 0
 PYMEM_ALLOCATOR_DEBUG = 2
@@ -348,7 +345,7 @@ class EmbeddingTests(EmbeddingTestsMixin, unittest.TestCase):
         out, err = self.run_embedded_interpreter("test_repeated_simple_init")
         self.assertEqual(out, 'Finalized\n' * INIT_LOOPS)
 
-    @requires_specialization
+    @support.requires_specialization
     def test_specialized_static_code_gets_unspecialized_at_Py_FINALIZE(self):
         # https://github.com/python/cpython/issues/92031
 
index 0b8299a32b03c0e1b4797e1296d54c1e1d7e5cb3..d0473500a177357c3c088e3c304bcbbe3f519d04 100644 (file)
@@ -7,8 +7,7 @@ import signal
 import subprocess
 import sys
 from test import support
-from test.support import os_helper
-from test.support import script_helper, is_android
+from test.support import os_helper, script_helper, is_android, MS_WINDOWS
 import tempfile
 import unittest
 from textwrap import dedent
@@ -22,7 +21,6 @@ if not support.has_subprocess_support:
     raise unittest.SkipTest("test module requires subprocess")
 
 TIMEOUT = 0.5
-MS_WINDOWS = (os.name == 'nt')
 
 
 def expected_traceback(lineno1, lineno2, header, min_count=1):
index d74075e456792d17f29951971b27888e6c7d2aac..99557739af6748cae6d393446b1dea475beabd11 100644 (file)
@@ -9,8 +9,7 @@ import unittest
 from test import support
 
 
-MS_WINDOWS = (os.name == 'nt')
-if MS_WINDOWS:
+if support.MS_WINDOWS:
     # On Windows, Python is usually built by MSVC. Passing /p:DebugSymbols=true
     # option to MSBuild produces PDB debug symbols, but gdb doesn't support PDB
     # debug symbol files.
index de2c4317e7143937353d0c5d425d8c918d595744..cfe8b579703cb6f65ac927e95b7ec6daae842bfe 100644 (file)
@@ -42,8 +42,6 @@ EXITCODE_NO_TESTS_RAN = 4
 EXITCODE_RERUN_FAIL = 5
 EXITCODE_INTERRUPTED = 130
 
-MS_WINDOWS = (sys.platform == 'win32')
-
 TEST_INTERRUPTED = textwrap.dedent("""
     from signal import SIGINT, raise_signal
     try:
@@ -2072,7 +2070,7 @@ class ArgsTestCase(BaseTestCase):
         self.check_executed_tests(output, testname,
                                   failed=[testname],
                                   stats=0, parallel=True)
-        if not MS_WINDOWS:
+        if not support.MS_WINDOWS:
             exitcode = -int(signal.SIGSEGV)
             self.assertIn(f"Exit code {exitcode} (SIGSEGV)", output)
         self.check_line(output, "just before crash!", full=True, regex=False)
index ec29ba6d51b127e8703d3547ce08a91c0e647561..f66881044e16dfa1c3db9e4824273a432ac1822c 100644 (file)
@@ -9,10 +9,9 @@ import textwrap
 import unittest
 from test import support
 from test.support.script_helper import assert_python_ok, assert_python_failure
-from test.support import os_helper
+from test.support import os_helper, MS_WINDOWS
 
 
-MS_WINDOWS = (sys.platform == 'win32')
 POSIX_LOCALES = ('C', 'POSIX')
 VXWORKS = (sys.platform == "vxworks")