Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "bpo-33671: Add support.MS_WINDOWS and support.MACOS (GH-7800)" #7919

Merged
merged 1 commit into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def join_process(process):
HAVE_GETVALUE = not getattr(_multiprocessing,
'HAVE_BROKEN_SEM_GETVALUE', False)

WIN32 = (sys.platform == "win32")

from multiprocessing.connection import wait

def wait_for_handle(handle, timeout):
Expand Down Expand Up @@ -3804,7 +3806,7 @@ def record(*args):

class TestInvalidHandle(unittest.TestCase):

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

class TestInvalidFamily(unittest.TestCase):

@unittest.skipIf(support.MS_WINDOWS, "skipped on Windows")
@unittest.skipIf(WIN32, "skipped on Windows")
def test_invalid_family(self):
with self.assertRaises(ValueError):
multiprocessing.connection.Listener(r'\\.\test')

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

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

def close(self, fd):
if support.MS_WINDOWS:
if WIN32:
socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd).close()
else:
os.close(fd)
Expand Down
53 changes: 20 additions & 33 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
"anticipate_failure", "load_package_tests", "detect_api_mismatch",
"check__all__", "skip_unless_bind_unix_socket",
# sys
"JYTHON", "ANDROID", "check_impl_detail", "unix_shell",
"setswitchinterval", "MS_WINDOWS", "MACOS",
"is_jython", "is_android", "check_impl_detail", "unix_shell",
"setswitchinterval",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
"bind_unix_socket",
Expand All @@ -108,21 +108,6 @@
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
]


# True if Python is running on Microsoft Windows.
MS_WINDOWS = (sys.platform == 'win32')

# True if Python is running on Apple macOS.
MACOS = (sys.platform == 'darwin')

# True if Python runs on Jython
# (Python implemented in Java running in a Java VM)
JYTHON = sys.platform.startswith('java')

# True if Python runs on Android
ANDROID = hasattr(sys, 'getandroidapilevel')


class Error(Exception):
"""Base class for regression test exceptions."""

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

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

if MS_WINDOWS:
unix_shell = None
elif ANDROID:
unix_shell = '/system/bin/sh'
is_jython = sys.platform.startswith('java')

is_android = hasattr(sys, 'getandroidapilevel')

if sys.platform != 'win32':
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = '/bin/sh'
unix_shell = None

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

# TESTFN_UNICODE is a non-ascii filename
TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f"
if MACOS:
if sys.platform == 'darwin':
# In Mac OS X's VFS API file names are, by definition, canonically
# decomposed Unicode, encoded using UTF-8. See QA1173:
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
Expand All @@ -879,7 +866,7 @@ def dec(*args, **kwargs):
# encoded by the filesystem encoding (in strict mode). It can be None if we
# cannot generate such filename.
TESTFN_UNENCODABLE = None
if MS_WINDOWS:
if os.name == 'nt':
# skip win32s (0) or Windows 9x/ME (1)
if sys.getwindowsversion().platform >= 2:
# Different kinds of characters from various languages to minimize the
Expand All @@ -894,8 +881,8 @@ def dec(*args, **kwargs):
'Unicode filename tests may not be effective'
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
TESTFN_UNENCODABLE = None
# macOS denies unencodable filenames (invalid utf-8)
elif not MACOS:
# Mac OS X denies unencodable filenames (invalid utf-8)
elif sys.platform != 'darwin':
try:
# ascii and utf-8 cannot encode the byte 0xff
b'\xff'.decode(TESTFN_ENCODING)
Expand Down Expand Up @@ -1536,7 +1523,7 @@ def gc_collect():
objects to disappear.
"""
gc.collect()
if JYTHON:
if is_jython:
time.sleep(0.1)
gc.collect()
gc.collect()
Expand Down Expand Up @@ -1995,7 +1982,7 @@ def _check_docstrings():
"""Just used to check if docstrings are enabled"""

MISSING_C_DOCSTRINGS = (check_impl_detail() and
not MS_WINDOWS and
sys.platform != 'win32' and
not sysconfig.get_config_var('WITH_DOC_STRINGS'))

HAVE_DOCSTRINGS = (_check_docstrings.__doc__ is not None and
Expand Down Expand Up @@ -2605,7 +2592,7 @@ def __enter__(self):
except (ValueError, OSError):
pass

if MACOS:
if sys.platform == 'darwin':
# Check if the 'Crash Reporter' on OSX was configured
# in 'Developer' mode and warn that it will get triggered
# when it is.
Expand Down Expand Up @@ -2749,7 +2736,7 @@ def setswitchinterval(interval):
# Setting a very low gil interval on the Android emulator causes python
# to hang (issue #26939).
minimum_interval = 1e-5
if ANDROID and interval < minimum_interval:
if is_android and interval < minimum_interval:
global _is_android_emulator
if _is_android_emulator is None:
_is_android_emulator = (subprocess.check_output(
Expand Down Expand Up @@ -2795,7 +2782,7 @@ def fd_count():
pass

old_modes = None
if MS_WINDOWS:
if sys.platform == 'win32':
# bpo-25306, bpo-31009: Call CrtSetReportMode() to not kill the process
# on invalid file descriptor if Python is compiled in debug mode
try:
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_c_locale_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Apply some platform dependent overrides
if sys.platform.startswith("linux"):
if test.support.ANDROID:
if test.support.is_android:
# Android defaults to using UTF-8 for all system interfaces
EXPECTED_C_LOCALE_STREAM_ENCODING = "utf-8"
EXPECTED_C_LOCALE_FS_ENCODING = "utf-8"
Expand Down Expand Up @@ -335,7 +335,7 @@ def _check_c_locale_coercion(self,
# locale environment variables are undefined or empty. When
# this code path is run with environ['LC_ALL'] == 'C', then
# LEGACY_LOCALE_WARNING is printed.
if (test.support.ANDROID and
if (test.support.is_android and
_expected_warnings == [CLI_COERCION_WARNING]):
_expected_warnings = None
self._check_child_encoding_details(base_var_dict,
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_cmd_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def test_undecodable_code(self):
if not stdout.startswith(pattern):
raise AssertionError("%a doesn't start with %a" % (stdout, pattern))

@unittest.skipUnless((support.MACOS or support.ANDROID),
'test specific to macOS and Android')
@unittest.skipUnless((sys.platform == 'darwin' or
support.is_android), 'test specific to Mac OS X and Android')
def test_osx_android_utf8(self):
def check_output(text):
decoded = text.decode('utf-8', 'surrogateescape')
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
Nick Mathewson
"""
import unittest
from test import support
from test.support import is_jython

from codeop import compile_command, PyCF_DONT_IMPLY_DEDENT
import io

if support.JYTHON:
if is_jython:
import sys

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

def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
if support.JYTHON:
if is_jython:
code = compile_command(str, "<input>", symbol)
self.assertTrue(code)
if symbol == "single":
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_valid(self):
av = self.assertValid

# special case
if not support.JYTHON:
if not is_jython:
self.assertEqual(compile_command(""),
compile("pass", "<input>", 'single',
PyCF_DONT_IMPLY_DEDENT))
Expand Down
15 changes: 8 additions & 7 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
import sys
from test import support
from test.support import script_helper
from test.support import script_helper, is_android
import tempfile
import threading
import unittest
Expand All @@ -18,6 +18,7 @@
_testcapi = None

TIMEOUT = 0.5
MS_WINDOWS = (os.name == 'nt')

def expected_traceback(lineno1, lineno2, header, min_count=1):
regex = header
Expand All @@ -30,7 +31,7 @@ def expected_traceback(lineno1, lineno2, header, min_count=1):

def skip_segfault_on_android(test):
# Issue #32138: Raising SIGSEGV on Android may not cause a crash.
return unittest.skipIf(support.ANDROID,
return unittest.skipIf(is_android,
'raising SIGSEGV on Android is unreliable')(test)

@contextmanager
Expand Down Expand Up @@ -120,7 +121,7 @@ def check_windows_exception(self, code, line_number, name_regex, **kw):
@unittest.skipIf(sys.platform.startswith('aix'),
"the first page of memory is a mapped read-only on AIX")
def test_read_null(self):
if not support.MS_WINDOWS:
if not MS_WINDOWS:
self.check_fatal_error("""
import faulthandler
faulthandler.enable()
Expand Down Expand Up @@ -731,7 +732,7 @@ def test_stderr_None(self):
with self.check_stderr_none():
faulthandler.register(signal.SIGUSR1)

@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_raise_exception(self):
for exc, name in (
('EXCEPTION_ACCESS_VIOLATION', 'access violation'),
Expand All @@ -746,7 +747,7 @@ def test_raise_exception(self):
3,
name)

@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_ignore_exception(self):
for exc_code in (
0xE06D7363, # MSC exception ("Emsc")
Expand All @@ -762,7 +763,7 @@ def test_ignore_exception(self):
self.assertEqual(output, [])
self.assertEqual(exitcode, exc_code)

@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_raise_nonfatal_exception(self):
# These exceptions are not strictly errors. Letting
# faulthandler display the traceback when they are
Expand Down Expand Up @@ -790,7 +791,7 @@ def test_raise_nonfatal_exception(self):
self.assertIn(exitcode,
(exc, exc & ~0x10000000))

@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
def test_disable_windows_exc_handler(self):
code = dedent("""
import faulthandler
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import test.support
from test.support import (
EnvironmentVarGuard, TESTFN, check_warnings, forget, JYTHON,
EnvironmentVarGuard, TESTFN, check_warnings, forget, is_jython,
make_legacy_pyc, rmtree, run_unittest, swap_attr, swap_item, temp_umask,
unlink, unload, create_empty_file, cpython_only, TESTFN_UNENCODABLE,
temp_dir, DirsOnSysPath)
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_import(self):
def test_with_extension(ext):
# The extension is normally ".py", perhaps ".pyw".
source = TESTFN + ext
if JYTHON:
if is_jython:
pyc = TESTFN + "$py.class"
else:
pyc = TESTFN + ".pyc"
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_large_file_ops(self):
# On Windows and Mac OSX this test consumes large resources; It takes
# a long time to build the >2 GiB file and takes >2 GiB of disk space
# therefore the resource must be enabled to run this test.
if support.MS_WINDOWS or support.MACOS:
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
support.requires(
'largefile',
'test requires %s bytes and a long time to run' % self.LARGE)
Expand Down
3 changes: 1 addition & 2 deletions Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import stat
import sys
import unittest
from test import support
from test.support import TESTFN, requires, unlink
import io # C implementation of io
import _pyio as pyio # Python implementation of io
Expand Down Expand Up @@ -146,7 +145,7 @@ def setUpModule():
# takes a long time to build the >2 GiB file and takes >2 GiB of disk
# space therefore the resource must be enabled to run this test.
# If not, nothing after this line stanza will be executed.
if support.MS_WINDOWS or support.MACOS:
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
requires('largefile',
'test requires %s bytes and a long time to run' % str(size))
else:
Expand Down
Loading