Skip to content

Commit 937ee9e

Browse files
authored
Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" (GH-7919)
This reverts commit 8fbbdf0.
1 parent fdd6e0b commit 937ee9e

16 files changed

+91
-95
lines changed

Lib/test/_test_multiprocessing.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def join_process(process):
103103
HAVE_GETVALUE = not getattr(_multiprocessing,
104104
'HAVE_BROKEN_SEM_GETVALUE', False)
105105

106+
WIN32 = (sys.platform == "win32")
107+
106108
from multiprocessing.connection import wait
107109

108110
def wait_for_handle(handle, timeout):
@@ -3804,7 +3806,7 @@ def record(*args):
38043806

38053807
class TestInvalidHandle(unittest.TestCase):
38063808

3807-
@unittest.skipIf(support.MS_WINDOWS, "skipped on Windows")
3809+
@unittest.skipIf(WIN32, "skipped on Windows")
38083810
def test_invalid_handles(self):
38093811
conn = multiprocessing.connection.Connection(44977608)
38103812
# check that poll() doesn't crash
@@ -4132,12 +4134,12 @@ def test_neg_timeout(self):
41324134

41334135
class TestInvalidFamily(unittest.TestCase):
41344136

4135-
@unittest.skipIf(support.MS_WINDOWS, "skipped on Windows")
4137+
@unittest.skipIf(WIN32, "skipped on Windows")
41364138
def test_invalid_family(self):
41374139
with self.assertRaises(ValueError):
41384140
multiprocessing.connection.Listener(r'\\.\test')
41394141

4140-
@unittest.skipUnless(support.MS_WINDOWS, "skipped on non-Windows platforms")
4142+
@unittest.skipUnless(WIN32, "skipped on non-Windows platforms")
41414143
def test_invalid_family_win32(self):
41424144
with self.assertRaises(ValueError):
41434145
multiprocessing.connection.Listener('/var/test.pipe')
@@ -4263,7 +4265,7 @@ def test_lock(self):
42634265
class TestCloseFds(unittest.TestCase):
42644266

42654267
def get_high_socket_fd(self):
4266-
if support.MS_WINDOWS:
4268+
if WIN32:
42674269
# The child process will not have any socket handles, so
42684270
# calling socket.fromfd() should produce WSAENOTSOCK even
42694271
# if there is a handle of the same number.
@@ -4281,7 +4283,7 @@ def get_high_socket_fd(self):
42814283
return fd
42824284

42834285
def close(self, fd):
4284-
if support.MS_WINDOWS:
4286+
if WIN32:
42854287
socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd).close()
42864288
else:
42874289
os.close(fd)

Lib/test/support/__init__.py

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@
9090
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
9191
"check__all__", "skip_unless_bind_unix_socket",
9292
# sys
93-
"JYTHON", "ANDROID", "check_impl_detail", "unix_shell",
94-
"setswitchinterval", "MS_WINDOWS", "MACOS",
93+
"is_jython", "is_android", "check_impl_detail", "unix_shell",
94+
"setswitchinterval",
9595
# network
9696
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
9797
"bind_unix_socket",
@@ -108,21 +108,6 @@
108108
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
109109
]
110110

111-
112-
# True if Python is running on Microsoft Windows.
113-
MS_WINDOWS = (sys.platform == 'win32')
114-
115-
# True if Python is running on Apple macOS.
116-
MACOS = (sys.platform == 'darwin')
117-
118-
# True if Python runs on Jython
119-
# (Python implemented in Java running in a Java VM)
120-
JYTHON = sys.platform.startswith('java')
121-
122-
# True if Python runs on Android
123-
ANDROID = hasattr(sys, 'getandroidapilevel')
124-
125-
126111
class Error(Exception):
127112
"""Base class for regression test exceptions."""
128113

@@ -499,7 +484,7 @@ class USEROBJECTFLAGS(ctypes.Structure):
499484
raise ctypes.WinError()
500485
if not bool(uof.dwFlags & WSF_VISIBLE):
501486
reason = "gui not available (WSF_VISIBLE flag not set)"
502-
elif MACOS:
487+
elif sys.platform == 'darwin':
503488
# The Aqua Tk implementations on OS X can abort the process if
504489
# being called in an environment where a window server connection
505490
# cannot be made, for instance when invoked by a buildbot or ssh
@@ -615,7 +600,7 @@ def requires_mac_ver(*min_version):
615600
def decorator(func):
616601
@functools.wraps(func)
617602
def wrapper(*args, **kw):
618-
if MACOS:
603+
if sys.platform == 'darwin':
619604
version_txt = platform.mac_ver()[0]
620605
try:
621606
version = tuple(map(int, version_txt.split('.')))
@@ -803,12 +788,14 @@ def dec(*args, **kwargs):
803788

804789
requires_lzma = unittest.skipUnless(lzma, 'requires lzma')
805790

806-
if MS_WINDOWS:
807-
unix_shell = None
808-
elif ANDROID:
809-
unix_shell = '/system/bin/sh'
791+
is_jython = sys.platform.startswith('java')
792+
793+
is_android = hasattr(sys, 'getandroidapilevel')
794+
795+
if sys.platform != 'win32':
796+
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
810797
else:
811-
unix_shell = '/bin/sh'
798+
unix_shell = None
812799

813800
# Filename used for testing
814801
if os.name == 'java':
@@ -867,7 +854,7 @@ def dec(*args, **kwargs):
867854

868855
# TESTFN_UNICODE is a non-ascii filename
869856
TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f"
870-
if MACOS:
857+
if sys.platform == 'darwin':
871858
# In Mac OS X's VFS API file names are, by definition, canonically
872859
# decomposed Unicode, encoded using UTF-8. See QA1173:
873860
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
@@ -879,7 +866,7 @@ def dec(*args, **kwargs):
879866
# encoded by the filesystem encoding (in strict mode). It can be None if we
880867
# cannot generate such filename.
881868
TESTFN_UNENCODABLE = None
882-
if MS_WINDOWS:
869+
if os.name == 'nt':
883870
# skip win32s (0) or Windows 9x/ME (1)
884871
if sys.getwindowsversion().platform >= 2:
885872
# Different kinds of characters from various languages to minimize the
@@ -894,8 +881,8 @@ def dec(*args, **kwargs):
894881
'Unicode filename tests may not be effective'
895882
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
896883
TESTFN_UNENCODABLE = None
897-
# macOS denies unencodable filenames (invalid utf-8)
898-
elif not MACOS:
884+
# Mac OS X denies unencodable filenames (invalid utf-8)
885+
elif sys.platform != 'darwin':
899886
try:
900887
# ascii and utf-8 cannot encode the byte 0xff
901888
b'\xff'.decode(TESTFN_ENCODING)
@@ -1536,7 +1523,7 @@ def gc_collect():
15361523
objects to disappear.
15371524
"""
15381525
gc.collect()
1539-
if JYTHON:
1526+
if is_jython:
15401527
time.sleep(0.1)
15411528
gc.collect()
15421529
gc.collect()
@@ -1995,7 +1982,7 @@ def _check_docstrings():
19951982
"""Just used to check if docstrings are enabled"""
19961983

19971984
MISSING_C_DOCSTRINGS = (check_impl_detail() and
1998-
not MS_WINDOWS and
1985+
sys.platform != 'win32' and
19991986
not sysconfig.get_config_var('WITH_DOC_STRINGS'))
20001987

20011988
HAVE_DOCSTRINGS = (_check_docstrings.__doc__ is not None and
@@ -2605,7 +2592,7 @@ def __enter__(self):
26052592
except (ValueError, OSError):
26062593
pass
26072594

2608-
if MACOS:
2595+
if sys.platform == 'darwin':
26092596
# Check if the 'Crash Reporter' on OSX was configured
26102597
# in 'Developer' mode and warn that it will get triggered
26112598
# when it is.
@@ -2749,7 +2736,7 @@ def setswitchinterval(interval):
27492736
# Setting a very low gil interval on the Android emulator causes python
27502737
# to hang (issue #26939).
27512738
minimum_interval = 1e-5
2752-
if ANDROID and interval < minimum_interval:
2739+
if is_android and interval < minimum_interval:
27532740
global _is_android_emulator
27542741
if _is_android_emulator is None:
27552742
_is_android_emulator = (subprocess.check_output(
@@ -2795,7 +2782,7 @@ def fd_count():
27952782
pass
27962783

27972784
old_modes = None
2798-
if MS_WINDOWS:
2785+
if sys.platform == 'win32':
27992786
# bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process
28002787
# on invalid file descriptor if Python is compiled in debug mode
28012788
try:

Lib/test/test_c_locale_coercion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
# Apply some platform dependent overrides
2929
if sys.platform.startswith("linux"):
30-
if test.support.ANDROID:
30+
if test.support.is_android:
3131
# Android defaults to using UTF-8 for all system interfaces
3232
EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8"
3333
EXPECTED_C_LOCALE_FS_ENCODING = "utf-8"
@@ -335,7 +335,7 @@ def _check_c_locale_coercion(self,
335335
# locale environment variables are undefined or empty. When
336336
# this code path is run with environ['LC_ALL'] == 'C', then
337337
# LEGACY_LOCALE_WARNING is printed.
338-
if (test.support.ANDROID and
338+
if (test.support.is_android and
339339
_expected_warnings == [CLI_COERCION_WARNING]):
340340
_expected_warnings = None
341341
self._check_child_encoding_details(base_var_dict,

Lib/test/test_cmd_line.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ def test_undecodable_code(self):
187187
if not stdout.startswith(pattern):
188188
raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
189189

190-
@unittest.skipUnless((support.MACOS or support.ANDROID),
191-
'test specific to macOS and Android')
190+
@unittest.skipUnless((sys.platform == 'darwin' or
191+
support.is_android), 'test specific to Mac OS X and Android')
192192
def test_osx_android_utf8(self):
193193
def check_output(text):
194194
decoded = text.decode('utf-8', 'surrogateescape')

Lib/test/test_codeop.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Nick Mathewson
44
"""
55
import unittest
6-
from test import support
6+
from test.support import is_jython
77

88
from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
99
import io
1010

11-
if support.JYTHON:
11+
if is_jython:
1212
import sys
1313

1414
def unify_callables(d):
@@ -21,7 +21,7 @@ class CodeopTests(unittest.TestCase):
2121

2222
def assertValid(self, str, symbol='single'):
2323
'''succeed iff str is a valid piece of code'''
24-
if support.JYTHON:
24+
if is_jython:
2525
code = compile_command(str, "<input>", symbol)
2626
self.assertTrue(code)
2727
if symbol == "single":
@@ -60,7 +60,7 @@ def test_valid(self):
6060
av = self.assertValid
6161

6262
# special case
63-
if not support.JYTHON:
63+
if not is_jython:
6464
self.assertEqual(compile_command(""),
6565
compile("pass", "<input>", 'single',
6666
PyCF_DONT_IMPLY_DEDENT))

Lib/test/test_faulthandler.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import subprocess
77
import sys
88
from test import support
9-
from test.support import script_helper
9+
from test.support import script_helper, is_android
1010
import tempfile
1111
import threading
1212
import unittest
@@ -18,6 +18,7 @@
1818
_testcapi = None
1919

2020
TIMEOUT = 0.5
21+
MS_WINDOWS = (os.name == 'nt')
2122

2223
def expected_traceback(lineno1, lineno2, header, min_count=1):
2324
regex = header
@@ -30,7 +31,7 @@ def expected_traceback(lineno1, lineno2, header, min_count=1):
3031

3132
def skip_segfault_on_android(test):
3233
# Issue #32138: Raising SIGSEGV on Android may not cause a crash.
33-
return unittest.skipIf(support.ANDROID,
34+
return unittest.skipIf(is_android,
3435
'raising SIGSEGV on Android is unreliable')(test)
3536

3637
@contextmanager
@@ -120,7 +121,7 @@ def check_windows_exception(self, code, line_number, name_regex, **kw):
120121
@unittest.skipIf(sys.platform.startswith('aix'),
121122
"the first page of memory is a mapped read-only on AIX")
122123
def test_read_null(self):
123-
if not support.MS_WINDOWS:
124+
if not MS_WINDOWS:
124125
self.check_fatal_error("""
125126
import faulthandler
126127
faulthandler.enable()
@@ -731,7 +732,7 @@ def test_stderr_None(self):
731732
with self.check_stderr_none():
732733
faulthandler.register(signal.SIGUSR1)
733734

734-
@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
735+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
735736
def test_raise_exception(self):
736737
for exc, name in (
737738
('EXCEPTION_ACCESS_VIOLATION', 'access violation'),
@@ -746,7 +747,7 @@ def test_raise_exception(self):
746747
3,
747748
name)
748749

749-
@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
750+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
750751
def test_ignore_exception(self):
751752
for exc_code in (
752753
0xE06D7363, # MSC exception ("Emsc")
@@ -762,7 +763,7 @@ def test_ignore_exception(self):
762763
self.assertEqual(output, [])
763764
self.assertEqual(exitcode, exc_code)
764765

765-
@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
766+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
766767
def test_raise_nonfatal_exception(self):
767768
# These exceptions are not strictly errors. Letting
768769
# faulthandler display the traceback when they are
@@ -790,7 +791,7 @@ def test_raise_nonfatal_exception(self):
790791
self.assertIn(exitcode,
791792
(exc, exc & ~0x10000000))
792793

793-
@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
794+
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
794795
def test_disable_windows_exc_handler(self):
795796
code = dedent("""
796797
import faulthandler

Lib/test/test_import/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import test.support
2222
from test.support import (
23-
EnvironmentVarGuard, TESTFN, check_warnings, forget, JYTHON,
23+
EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
2424
make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask,
2525
unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE,
2626
temp_dir, DirsOnSysPath)
@@ -148,7 +148,7 @@ def test_import(self):
148148
def test_with_extension(ext):
149149
# The extension is normally ".py", perhaps ".pyw".
150150
source = TESTFN + ext
151-
if JYTHON:
151+
if is_jython:
152152
pyc = TESTFN + "$py.class"
153153
else:
154154
pyc = TESTFN + ".pyc"

Lib/test/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def test_large_file_ops(self):
583583
# On Windows and Mac OSX this test consumes large resources; It takes
584584
# a long time to build the >2 GiB file and takes >2 GiB of disk space
585585
# therefore the resource must be enabled to run this test.
586-
if support.MS_WINDOWS or support.MACOS:
586+
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
587587
support.requires(
588588
'largefile',
589589
'test requires %s bytes and a long time to run' % self.LARGE)

Lib/test/test_largefile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import stat
66
import sys
77
import unittest
8-
from test import support
98
from test.support import TESTFN, requires, unlink
109
import io # C implementation of io
1110
import _pyio as pyio # Python implementation of io
@@ -146,7 +145,7 @@ def setUpModule():
146145
# takes a long time to build the >2 GiB file and takes >2 GiB of disk
147146
# space therefore the resource must be enabled to run this test.
148147
# If not, nothing after this line stanza will be executed.
149-
if support.MS_WINDOWS or support.MACOS:
148+
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
150149
requires('largefile',
151150
'test requires %s bytes and a long time to run' % str(size))
152151
else:

0 commit comments

Comments
 (0)