Skip to content
Closed
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
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ in a standardized and extensible format, and offers several other benefits.
(Contributed by C.A.M. Gerlach in :issue:`36268`.)


test
----

The :mod:`test` module now uses ``CONSTANTS`` for the major platforms
(``AIX``, ``ANDROID``, ``LINUX``, ``JYTHON``, ``MACOS``, ``MS_WINDOWS``)
to standardize the style compared to the current practice of some constants
and different styles of sys.platform and platform.system().
The constants are defined in `test.support`.
(Contributed by M. Felt in :issue:`36624`.)

threading
---------

Expand Down
35 changes: 16 additions & 19 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import test.support
import test.support.script_helper
from test import support
from test.support import LINUX, MACOS, MS_WINDOWS


# Skip tests if _multiprocessing wasn't built.
Expand Down Expand Up @@ -116,8 +117,6 @@ def _resource_unlink(name, rtype):
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 @@ -574,7 +573,7 @@ def test_many_processes(self):
join_process(p)
if os.name != 'nt':
exitcodes = [-signal.SIGTERM]
if sys.platform == 'darwin':
if MACOS:
# bpo-31510: On macOS, killing a freshly started process with
# SIGTERM sometimes kills the process with SIGKILL.
exitcodes.append(-signal.SIGKILL)
Expand Down Expand Up @@ -1553,7 +1552,7 @@ def _test_wait_result(cls, c, pid):
os.kill(pid, signal.SIGINT)

def test_wait_result(self):
if isinstance(self, ProcessesMixin) and sys.platform != 'win32':
if isinstance(self, ProcessesMixin) and not MS_WINDOWS:
pid = os.getpid()
else:
pid = None
Expand Down Expand Up @@ -3162,8 +3161,7 @@ def test_fd_transfer(self):
self.assertEqual(f.read(), b"foo")

@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@unittest.skipIf(sys.platform == "win32",
"test semantics don't make sense on Windows")
@unittest.skipIf(MS_WINDOWS, "test semantics don't make sense on Windows")
@unittest.skipIf(MAXFD <= 256,
"largest assignable fd number is too small")
@unittest.skipUnless(hasattr(os, "dup2"),
Expand Down Expand Up @@ -3199,7 +3197,7 @@ def _send_data_without_fd(self, conn):
os.write(conn.fileno(), b"\0")

@unittest.skipUnless(HAS_REDUCTION, "test needs multiprocessing.reduction")
@unittest.skipIf(sys.platform == "win32", "doesn't make sense on Windows")
@unittest.skipIf(MS_WINDOWS, "doesn't make sense on Windows")
def test_missing_fd_transfer(self):
# Check that exception is raised when received data is not
# accompanied by a file descriptor in ancillary data.
Expand Down Expand Up @@ -3858,7 +3856,7 @@ def test_shared_memory_SharedMemoryManager_basics(self):
self.assertGreaterEqual(len(doppleganger_shm0.buf), 32)
held_name = lom[0].name
smm1.shutdown()
if sys.platform != "win32":
if not MS_WINDOWS:
# Calls to unlink() have no effect on Windows platform; shared
# memory will only be released once final process exits.
with self.assertRaises(FileNotFoundError):
Expand All @@ -3869,7 +3867,7 @@ def test_shared_memory_SharedMemoryManager_basics(self):
sl = smm2.ShareableList("howdy")
shm = smm2.SharedMemory(size=128)
held_name = sl.shm.name
if sys.platform != "win32":
if not MS_WINDOWS:
with self.assertRaises(FileNotFoundError):
# No longer there to be attached to again.
absent_sl = shared_memory.ShareableList(name=held_name)
Expand Down Expand Up @@ -4165,7 +4163,7 @@ def get_module_names(self):

def test_import(self):
modules = self.get_module_names()
if sys.platform == 'win32':
if MS_WINDOWS:
modules.remove('multiprocessing.popen_fork')
modules.remove('multiprocessing.popen_forkserver')
modules.remove('multiprocessing.popen_spawn_posix')
Expand Down Expand Up @@ -4298,7 +4296,7 @@ def record(*args):

class TestInvalidHandle(unittest.TestCase):

@unittest.skipIf(WIN32, "skipped on Windows")
@unittest.skipIf(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 @@ -4624,12 +4622,12 @@ def test_neg_timeout(self):

class TestInvalidFamily(unittest.TestCase):

@unittest.skipIf(WIN32, "skipped on Windows")
@unittest.skipIf(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(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 @@ -4755,7 +4753,7 @@ def test_lock(self):
class TestCloseFds(unittest.TestCase):

def get_high_socket_fd(self):
if WIN32:
if 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 @@ -4773,7 +4771,7 @@ def get_high_socket_fd(self):
return fd

def close(self, fd):
if WIN32:
if MS_WINDOWS:
socket.socket(socket.AF_INET, socket.SOCK_STREAM, fileno=fd).close()
else:
os.close(fd)
Expand Down Expand Up @@ -4936,7 +4934,7 @@ def test_set_get(self):

def test_get_all(self):
methods = multiprocessing.get_all_start_methods()
if sys.platform == 'win32':
if MS_WINDOWS:
self.assertEqual(methods, ['spawn'])
else:
self.assertTrue(methods == ['fork', 'spawn'] or
Expand All @@ -4955,8 +4953,7 @@ def test_preload_resources(self):
self.fail("failed spawning forkserver or grandchild")


@unittest.skipIf(sys.platform == "win32",
"test semantics don't make sense on Windows")
@unittest.skipIf(MS_WINDOWS, "test semantics don't make sense on Windows")
class TestResourceTracker(unittest.TestCase):

def test_resource_tracker(self):
Expand Down Expand Up @@ -5603,7 +5600,7 @@ def setUpModule():
raise unittest.SkipTest(start_method +
' start method not supported')

if sys.platform.startswith("linux"):
if LINUX:
try:
lock = multiprocessing.RLock()
except OSError:
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/datetimetester.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
"""
from test.support import is_resource_enabled
from test.support import is_resource_enabled, MS_WINDOWS

import itertools
import bisect
Expand Down Expand Up @@ -2453,13 +2453,13 @@ def test_insane_utcfromtimestamp(self):
self.assertRaises(OverflowError, self.theclass.utcfromtimestamp,
insane)

@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
@unittest.skipIf(MS_WINDOWS, "Windows doesn't accept negative timestamps")
def test_negative_float_fromtimestamp(self):
# The result is tz-dependent; at least test that this doesn't
# fail (like it did before bug 1646728 was fixed).
self.theclass.fromtimestamp(-1.05)

@unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
@unittest.skipIf(MS_WINDOWS, "Windows doesn't accept negative timestamps")
def test_negative_float_utcfromtimestamp(self):
d = self.theclass.utcfromtimestamp(-1.05)
self.assertEqual(d, self.theclass(1969, 12, 31, 23, 59, 58, 950000))
Expand Down Expand Up @@ -5700,7 +5700,7 @@ class ZoneInfoTest(unittest.TestCase):
zonename = 'America/New_York'

def setUp(self):
if sys.platform == "win32":
if MS_WINDOWS:
self.skipTest("Skipping zoneinfo tests on Windows")
try:
self.tz = ZoneInfo.fromname(self.zonename)
Expand Down
10 changes: 4 additions & 6 deletions Lib/test/eintrdata/eintr_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest

from test import support
from test.support import MACOS

@contextlib.contextmanager
def kill_on_error(proc):
Expand Down Expand Up @@ -347,8 +348,7 @@ def python_open(self, path):
fp = open(path, 'w')
fp.close()

@unittest.skipIf(sys.platform == "darwin",
"hangs under macOS; see bpo-25234, bpo-35363")
@unittest.skipIf(MACOS, "hangs under macOS; see bpo-25234, bpo-35363")
def test_open(self):
self._test_open("fp = open(path, 'r')\nfp.close()",
self.python_open)
Expand All @@ -357,8 +357,7 @@ def os_open(self, path):
fd = os.open(path, os.O_WRONLY)
os.close(fd)

@unittest.skipIf(sys.platform == "darwin",
"hangs under macOS; see bpo-25234, bpo-35363")
@unittest.skipIf(MACOS, "hangs under macOS; see bpo-25234, bpo-35363")
def test_os_open(self):
self._test_open("fd = os.open(path, os.O_RDONLY)\nos.close(fd)",
self.os_open)
Expand Down Expand Up @@ -439,8 +438,7 @@ def test_select(self):
self.stop_alarm()
self.assertGreaterEqual(dt, self.sleep_time)

@unittest.skipIf(sys.platform == "darwin",
"poll may fail on macOS; see issue #28087")
@unittest.skipIf(MACOS, "poll may fail on macOS; see issue #28087")
@unittest.skipUnless(hasattr(select, 'poll'), 'need select.poll')
def test_poll(self):
poller = select.poll()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def _main(self, tests, kwargs):

# If we're on windows and this is the parent runner (not a worker),
# track the load average.
if sys.platform == 'win32' and self.worker_test_name is None:
if support.MS_WINDOWS and self.worker_test_name is None:
from test.libregrtest.win_utils import WindowsLoadTracker

try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def setup_tests(ns):
# fix is to set the stack limit to 2048.
# This approach may also be useful for other Unixy platforms that
# suffer from small default stack limits.
if sys.platform == 'darwin':
if support.MACOS:
try:
import resource
except ImportError:
Expand Down
Loading