Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 5 additions & 7 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ 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 @@ -3806,7 +3804,7 @@ def record(*args):

class TestInvalidHandle(unittest.TestCase):

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

class TestInvalidFamily(unittest.TestCase):

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

@unittest.skipUnless(WIN32, "skipped on non-Windows platforms")
@unittest.skipUnless(support.MS_WINDOWS, "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 @@ -4265,7 +4263,7 @@ def test_lock(self):
class TestCloseFds(unittest.TestCase):

def get_high_socket_fd(self):
if WIN32:
if support.MS_WINDOWS:
# 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 @@ -4283,7 +4281,7 @@ def get_high_socket_fd(self):
return fd

def close(self, fd):
if WIN32:
if support.MS_WINDOWS:
socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd).close()
else:
os.close(fd)
Expand Down
38 changes: 23 additions & 15 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"check__all__", "skip_unless_bind_unix_socket",
# sys
"is_jython", "is_android", "check_impl_detail", "unix_shell",
"setswitchinterval",
"setswitchinterval", "MS_WINDOWS", "MACOS",
# network
"HOST", "IPV6_ENABLED", "find_unused_port", "bind_port", "open_urlresource",
"bind_unix_socket",
Expand All @@ -108,6 +108,18 @@
"run_with_tz", "PGO", "missing_compiler_executable", "fd_count",
]


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we happy this is suitable for replacing all of the following without changing behaviour?

mswindows = (sys.platform == "win32")
MS_WINDOWS = (sys.platform == 'win32')
MS_WINDOWS = (os.name == 'nt')
WIN32 = (sys.platform == "win32")
sys.platform[:3] == 'win'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sys.platform[:3] == 'win'

On "win64", Python uses "win32" as well.

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

I'm not sure about Cygwin which is a strange beast.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to use is_windows and is_macos for uniformity with is_jython and is_android?

Or rename the latter two?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replied here: #7800 (comment)

If we do something, I would prefer to rename is_android and is_jython to ANDROID and JYTHON to be more consistent with PEP 8 and existing code (rather than adding support.is_windows and support.is_macos).


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here:

MACOS = sys.platform.startswith("darwin")
sys.platform == 'darwin'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MACOS = sys.platform.startswith("darwin")

I don't see the purpose of this test. sys.platform is always the "darwin" string on macOS, no?


is_jython = sys.platform.startswith('java')

is_android = hasattr(sys, 'getandroidapilevel')


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

Expand Down Expand Up @@ -484,7 +496,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 sys.platform == 'darwin':
elif MACOS:
# 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 @@ -600,7 +612,7 @@ def requires_mac_ver(*min_version):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kw):
if sys.platform == 'darwin':
if MACOS:
version_txt = platform.mac_ver()[0]
try:
version = tuple(map(int, version_txt.split('.')))
Expand Down Expand Up @@ -788,11 +800,7 @@ def dec(*args, **kwargs):

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

is_jython = sys.platform.startswith('java')

is_android = hasattr(sys, 'getandroidapilevel')

if sys.platform != 'win32':
if not MS_WINDOWS:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if MS_WINDOWS:
    ...
elif is_androif:
    ...
else:
    ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, this change is unrelated, but ok, let's do that :-)

unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = None
Expand Down Expand Up @@ -854,7 +862,7 @@ def dec(*args, **kwargs):

# TESTFN_UNICODE is a non-ascii filename
TESTFN_UNICODE = TESTFN + "-\xe0\xf2\u0258\u0141\u011f"
if sys.platform == 'darwin':
if MACOS:
# 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 @@ -866,7 +874,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 os.name == 'nt':
if MS_WINDOWS:
# 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 @@ -881,8 +889,8 @@ def dec(*args, **kwargs):
'Unicode filename tests may not be effective'
% (TESTFN_UNENCODABLE, TESTFN_ENCODING))
TESTFN_UNENCODABLE = None
# Mac OS X denies unencodable filenames (invalid utf-8)
elif sys.platform != 'darwin':
# macOS denies unencodable filenames (invalid utf-8)
elif not MACOS:
try:
# ascii and utf-8 cannot encode the byte 0xff
b'\xff'.decode(TESTFN_ENCODING)
Expand Down Expand Up @@ -1982,7 +1990,7 @@ def _check_docstrings():
"""Just used to check if docstrings are enabled"""

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

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

if sys.platform == 'darwin':
if MACOS:
# 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 @@ -2782,7 +2790,7 @@ def fd_count():
pass

old_modes = None
if sys.platform == 'win32':
if MS_WINDOWS:
# 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
11 changes: 5 additions & 6 deletions Lib/test/test_faulthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
_testcapi = None

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

def expected_traceback(lineno1, lineno2, header, min_count=1):
regex = header
Expand Down Expand Up @@ -121,7 +120,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 MS_WINDOWS:
if not support.MS_WINDOWS:
self.check_fatal_error("""
import faulthandler
faulthandler.enable()
Expand Down Expand Up @@ -732,7 +731,7 @@ def test_stderr_None(self):
with self.check_stderr_none():
faulthandler.register(signal.SIGUSR1)

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

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

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(support.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 @@ -791,7 +790,7 @@ def test_raise_nonfatal_exception(self):
self.assertIn(exitcode,
(exc, exc & ~0x10000000))

@unittest.skipUnless(MS_WINDOWS, 'specific to Windows')
@unittest.skipUnless(support.MS_WINDOWS, 'specific to Windows')
def test_disable_windows_exc_handler(self):
code = dedent("""
import faulthandler
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 sys.platform[:3] == 'win' or sys.platform == 'darwin':
if support.MS_WINDOWS or support.MACOS:
support.requires(
'largefile',
'test requires %s bytes and a long time to run' % self.LARGE)
Expand Down
3 changes: 2 additions & 1 deletion Lib/test/test_largefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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 @@ -145,7 +146,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 sys.platform[:3] == 'win' or sys.platform == 'darwin':
if support.MS_WINDOWS or support.MACOS:
requires('largefile',
'test requires %s bytes and a long time to run' % str(size))
else:
Expand Down
6 changes: 2 additions & 4 deletions Lib/test/test_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ def test_libc_ver(self):
res = platform.libc_ver(executable)

def test_popen(self):
mswindows = (sys.platform == "win32")

if mswindows:
if support.MS_WINDOWS:
command = '"{}" -c "print(\'Hello\')"'.format(sys.executable)
else:
command = "'{}' -c 'print(\"Hello\")'".format(sys.executable)
Expand All @@ -284,7 +282,7 @@ def test_popen(self):
self.assertEqual(hello, "Hello")

data = 'plop'
if mswindows:
if support.MS_WINDOWS:
command = '"{}" -c "import sys; data=sys.stdin.read(); exit(len(data))"'
else:
command = "'{}' -c 'import sys; data=sys.stdin.read(); exit(len(data))'"
Expand Down
9 changes: 4 additions & 5 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from test.support import TESTFN, FakePath

TESTFN2 = TESTFN + "2"
MACOS = sys.platform.startswith("darwin")
try:
import grp
import pwd
Expand Down Expand Up @@ -1808,7 +1807,7 @@ def _open(filename, mode='r'):

self.assertRaises(OSError, shutil.copyfile, 'srcfile', 'destfile')

@unittest.skipIf(MACOS, "skipped on macOS")
@unittest.skipIf(support.MACOS, "skipped on macOS")
def test_w_dest_open_fails(self):

srcfile = self.Faux()
Expand All @@ -1828,7 +1827,7 @@ def _open(filename, mode='r'):
self.assertEqual(srcfile._exited_with[1].args,
('Cannot open "destfile"',))

@unittest.skipIf(MACOS, "skipped on macOS")
@unittest.skipIf(support.MACOS, "skipped on macOS")
def test_w_dest_close_fails(self):

srcfile = self.Faux()
Expand All @@ -1851,7 +1850,7 @@ def _open(filename, mode='r'):
self.assertEqual(srcfile._exited_with[1].args,
('Cannot close',))

@unittest.skipIf(MACOS, "skipped on macOS")
@unittest.skipIf(support.MACOS, "skipped on macOS")
def test_w_source_close_fails(self):

srcfile = self.Faux(True)
Expand Down Expand Up @@ -2185,7 +2184,7 @@ def test_file2file_not_supported(self):
shutil._HAS_SENDFILE = True


@unittest.skipIf(not MACOS, 'macOS only')
@unittest.skipIf(not support.MACOS, 'macOS only')
class TestZeroCopyMACOS(_ZeroCopyFileTest, unittest.TestCase):
PATCHPOINT = "posix._fcopyfile"

Expand Down
Loading