Skip to content

Commit 391659b

Browse files
authoredFeb 5, 2024
gh-114099: Add test exclusions to support running the test suite on iOS (#114889)
Add test annotations required to run the test suite on iOS (PEP 730). The majority of the change involve annotating tests that use subprocess, but are skipped on Emscripten/WASI for other reasons, and including iOS/tvOS/watchOS under the same umbrella as macOS/darwin checks. `is_apple` and `is_apple_mobile` test helpers have been added to identify *any* Apple platform, and "any Apple platform except macOS", respectively.
1 parent 15f6f04 commit 391659b

31 files changed

+224
-150
lines changed
 

‎Lib/test/support/__init__.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"requires_limited_api", "requires_specialization",
4444
# sys
4545
"MS_WINDOWS", "is_jython", "is_android", "is_emscripten", "is_wasi",
46-
"check_impl_detail", "unix_shell", "setswitchinterval",
46+
"is_apple_mobile", "check_impl_detail", "unix_shell", "setswitchinterval",
4747
# os
4848
"get_pagesize",
4949
# network
@@ -522,7 +522,7 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
522522

523523
is_android = hasattr(sys, 'getandroidapilevel')
524524

525-
if sys.platform not in ('win32', 'vxworks'):
525+
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
526526
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
527527
else:
528528
unix_shell = None
@@ -532,19 +532,35 @@ def requires_debug_ranges(reason='requires co_positions / debug_ranges'):
532532
is_emscripten = sys.platform == "emscripten"
533533
is_wasi = sys.platform == "wasi"
534534

535-
has_fork_support = hasattr(os, "fork") and not is_emscripten and not is_wasi
535+
# Apple mobile platforms (iOS/tvOS/watchOS) are POSIX-like but do not
536+
# have subprocess or fork support.
537+
is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
538+
is_apple = is_apple_mobile or sys.platform == "darwin"
539+
540+
has_fork_support = hasattr(os, "fork") and not (
541+
is_emscripten
542+
or is_wasi
543+
or is_apple_mobile
544+
)
536545

537546
def requires_fork():
538547
return unittest.skipUnless(has_fork_support, "requires working os.fork()")
539548

540-
has_subprocess_support = not is_emscripten and not is_wasi
549+
has_subprocess_support = not (
550+
is_emscripten
551+
or is_wasi
552+
or is_apple_mobile
553+
)
541554

542555
def requires_subprocess():
543556
"""Used for subprocess, os.spawn calls, fd inheritance"""
544557
return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
545558

546559
# Emscripten's socket emulation and WASI sockets have limitations.
547-
has_socket_support = not is_emscripten and not is_wasi
560+
has_socket_support = not (
561+
is_emscripten
562+
or is_wasi
563+
)
548564

549565
def requires_working_socket(*, module=False):
550566
"""Skip tests or modules that require working sockets

‎Lib/test/support/os_helper.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
# TESTFN_UNICODE is a non-ascii filename
2424
TESTFN_UNICODE = TESTFN_ASCII + "-\xe0\xf2\u0258\u0141\u011f"
25-
if sys.platform == 'darwin':
26-
# In Mac OS X's VFS API file names are, by definition, canonically
25+
if support.is_apple:
26+
# On Apple's VFS API file names are, by definition, canonically
2727
# decomposed Unicode, encoded using UTF-8. See QA1173:
2828
# http://developer.apple.com/mac/library/qa/qa2001/qa1173.html
2929
import unicodedata
@@ -48,8 +48,8 @@
4848
'encoding (%s). Unicode filename tests may not be effective'
4949
% (TESTFN_UNENCODABLE, sys.getfilesystemencoding()))
5050
TESTFN_UNENCODABLE = None
51-
# macOS and Emscripten deny unencodable filenames (invalid utf-8)
52-
elif sys.platform not in {'darwin', 'emscripten', 'wasi'}:
51+
# Apple and Emscripten deny unencodable filenames (invalid utf-8)
52+
elif not support.is_apple and sys.platform not in {"emscripten", "wasi"}:
5353
try:
5454
# ascii and utf-8 cannot encode the byte 0xff
5555
b'\xff'.decode(sys.getfilesystemencoding())

‎Lib/test/test_asyncio/test_events.py

+14
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,7 @@ def check_killed(self, returncode):
18151815
else:
18161816
self.assertEqual(-signal.SIGKILL, returncode)
18171817

1818+
@support.requires_subprocess()
18181819
def test_subprocess_exec(self):
18191820
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
18201821

@@ -1836,6 +1837,7 @@ def test_subprocess_exec(self):
18361837
self.check_killed(proto.returncode)
18371838
self.assertEqual(b'Python The Winner', proto.data[1])
18381839

1840+
@support.requires_subprocess()
18391841
def test_subprocess_interactive(self):
18401842
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
18411843

@@ -1863,6 +1865,7 @@ def test_subprocess_interactive(self):
18631865
self.loop.run_until_complete(proto.completed)
18641866
self.check_killed(proto.returncode)
18651867

1868+
@support.requires_subprocess()
18661869
def test_subprocess_shell(self):
18671870
connect = self.loop.subprocess_shell(
18681871
functools.partial(MySubprocessProtocol, self.loop),
@@ -1879,6 +1882,7 @@ def test_subprocess_shell(self):
18791882
self.assertEqual(proto.data[2], b'')
18801883
transp.close()
18811884

1885+
@support.requires_subprocess()
18821886
def test_subprocess_exitcode(self):
18831887
connect = self.loop.subprocess_shell(
18841888
functools.partial(MySubprocessProtocol, self.loop),
@@ -1890,6 +1894,7 @@ def test_subprocess_exitcode(self):
18901894
self.assertEqual(7, proto.returncode)
18911895
transp.close()
18921896

1897+
@support.requires_subprocess()
18931898
def test_subprocess_close_after_finish(self):
18941899
connect = self.loop.subprocess_shell(
18951900
functools.partial(MySubprocessProtocol, self.loop),
@@ -1904,6 +1909,7 @@ def test_subprocess_close_after_finish(self):
19041909
self.assertEqual(7, proto.returncode)
19051910
self.assertIsNone(transp.close())
19061911

1912+
@support.requires_subprocess()
19071913
def test_subprocess_kill(self):
19081914
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
19091915

@@ -1920,6 +1926,7 @@ def test_subprocess_kill(self):
19201926
self.check_killed(proto.returncode)
19211927
transp.close()
19221928

1929+
@support.requires_subprocess()
19231930
def test_subprocess_terminate(self):
19241931
prog = os.path.join(os.path.dirname(__file__), 'echo.py')
19251932

@@ -1937,6 +1944,7 @@ def test_subprocess_terminate(self):
19371944
transp.close()
19381945

19391946
@unittest.skipIf(sys.platform == 'win32', "Don't have SIGHUP")
1947+
@support.requires_subprocess()
19401948
def test_subprocess_send_signal(self):
19411949
# bpo-31034: Make sure that we get the default signal handler (killing
19421950
# the process). The parent process may have decided to ignore SIGHUP,
@@ -1961,6 +1969,7 @@ def test_subprocess_send_signal(self):
19611969
finally:
19621970
signal.signal(signal.SIGHUP, old_handler)
19631971

1972+
@support.requires_subprocess()
19641973
def test_subprocess_stderr(self):
19651974
prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
19661975

@@ -1982,6 +1991,7 @@ def test_subprocess_stderr(self):
19821991
self.assertTrue(proto.data[2].startswith(b'ERR:test'), proto.data[2])
19831992
self.assertEqual(0, proto.returncode)
19841993

1994+
@support.requires_subprocess()
19851995
def test_subprocess_stderr_redirect_to_stdout(self):
19861996
prog = os.path.join(os.path.dirname(__file__), 'echo2.py')
19871997

@@ -2007,6 +2017,7 @@ def test_subprocess_stderr_redirect_to_stdout(self):
20072017
transp.close()
20082018
self.assertEqual(0, proto.returncode)
20092019

2020+
@support.requires_subprocess()
20102021
def test_subprocess_close_client_stream(self):
20112022
prog = os.path.join(os.path.dirname(__file__), 'echo3.py')
20122023

@@ -2041,6 +2052,7 @@ def test_subprocess_close_client_stream(self):
20412052
self.loop.run_until_complete(proto.completed)
20422053
self.check_killed(proto.returncode)
20432054

2055+
@support.requires_subprocess()
20442056
def test_subprocess_wait_no_same_group(self):
20452057
# start the new process in a new session
20462058
connect = self.loop.subprocess_shell(
@@ -2053,6 +2065,7 @@ def test_subprocess_wait_no_same_group(self):
20532065
self.assertEqual(7, proto.returncode)
20542066
transp.close()
20552067

2068+
@support.requires_subprocess()
20562069
def test_subprocess_exec_invalid_args(self):
20572070
async def connect(**kwds):
20582071
await self.loop.subprocess_exec(
@@ -2066,6 +2079,7 @@ async def connect(**kwds):
20662079
with self.assertRaises(ValueError):
20672080
self.loop.run_until_complete(connect(shell=True))
20682081

2082+
@support.requires_subprocess()
20692083
def test_subprocess_shell_invalid_args(self):
20702084

20712085
async def connect(cmd=None, **kwds):

‎Lib/test/test_asyncio/test_streams.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
import unittest
1111
from unittest import mock
1212
import warnings
13-
from test.support import socket_helper
1413
try:
1514
import ssl
1615
except ImportError:
1716
ssl = None
1817

1918
import asyncio
2019
from test.test_asyncio import utils as test_utils
20+
from test.support import requires_subprocess, socket_helper
2121

2222

2323
def tearDownModule():
@@ -770,6 +770,7 @@ async def client(addr):
770770
self.assertEqual(msg2, b"hello world 2!\n")
771771

772772
@unittest.skipIf(sys.platform == 'win32', "Don't have pipes")
773+
@requires_subprocess()
773774
def test_read_all_from_pipe_reader(self):
774775
# See asyncio issue 168. This test is derived from the example
775776
# subprocess_attach_read_pipe.py, but we configure the

‎Lib/test/test_asyncio/test_subprocess.py

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def _start(self, *args, **kwargs):
4747
self._proc.pid = -1
4848

4949

50+
@support.requires_subprocess()
5051
class SubprocessTransportTests(test_utils.TestCase):
5152
def setUp(self):
5253
super().setUp()
@@ -110,6 +111,7 @@ def test_subprocess_repr(self):
110111
transport.close()
111112

112113

114+
@support.requires_subprocess()
113115
class SubprocessMixin:
114116

115117
def test_stdin_stdout(self):

‎Lib/test/test_asyncio/test_unix_events.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1874,7 +1874,7 @@ async def runner():
18741874
wsock.close()
18751875

18761876

1877-
@unittest.skipUnless(hasattr(os, 'fork'), 'requires os.fork()')
1877+
@support.requires_fork()
18781878
class TestFork(unittest.IsolatedAsyncioTestCase):
18791879

18801880
async def test_fork_not_share_event_loop(self):

‎Lib/test/test_cmd_line_script.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import textwrap
1616
from test import support
17-
from test.support import import_helper
18-
from test.support import os_helper
17+
from test.support import import_helper, is_apple, os_helper
1918
from test.support.script_helper import (
2019
make_pkg, make_script, make_zip_pkg, make_zip_script,
2120
assert_python_ok, assert_python_failure, spawn_python, kill_python)
@@ -557,12 +556,17 @@ def test_pep_409_verbiage(self):
557556
self.assertTrue(text[3].startswith('NameError'))
558557

559558
def test_non_ascii(self):
560-
# Mac OS X denies the creation of a file with an invalid UTF-8 name.
559+
# Apple platforms deny the creation of a file with an invalid UTF-8 name.
561560
# Windows allows creating a name with an arbitrary bytes name, but
562561
# Python cannot a undecodable bytes argument to a subprocess.
563-
# WASI does not permit invalid UTF-8 names.
564-
if (os_helper.TESTFN_UNDECODABLE
565-
and sys.platform not in ('win32', 'darwin', 'emscripten', 'wasi')):
562+
# Emscripten/WASI does not permit invalid UTF-8 names.
563+
if (
564+
os_helper.TESTFN_UNDECODABLE
565+
and sys.platform not in {
566+
"win32", "emscripten", "wasi"
567+
}
568+
and not is_apple
569+
):
566570
name = os.fsdecode(os_helper.TESTFN_UNDECODABLE)
567571
elif os_helper.TESTFN_NONASCII:
568572
name = os_helper.TESTFN_NONASCII

‎Lib/test/test_code_module.py

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def setUp(self):
160160
self.console = code.InteractiveConsole(local_exit=True)
161161
self.mock_sys()
162162

163+
@unittest.skipIf(sys.flags.no_site, "exit() isn't defined unless there's a site module")
163164
def test_exit(self):
164165
# default exit message
165166
self.infunc.side_effect = ["exit()"]

‎Lib/test/test_fcntl.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import struct
77
import sys
88
import unittest
9-
from test.support import verbose, cpython_only, get_pagesize
9+
from test.support import (
10+
cpython_only, get_pagesize, is_apple, requires_subprocess, verbose
11+
)
1012
from test.support.import_helper import import_module
1113
from test.support.os_helper import TESTFN, unlink
1214

@@ -56,8 +58,10 @@ def get_lockdata():
5658
else:
5759
start_len = "qq"
5860

59-
if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd'))
60-
or sys.platform == 'darwin'):
61+
if (
62+
sys.platform.startswith(('netbsd', 'freebsd', 'openbsd'))
63+
or is_apple
64+
):
6165
if struct.calcsize('l') == 8:
6266
off_t = 'l'
6367
pid_t = 'i'
@@ -157,6 +161,7 @@ def test_flock(self):
157161
self.assertRaises(TypeError, fcntl.flock, 'spam', fcntl.LOCK_SH)
158162

159163
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
164+
@requires_subprocess()
160165
def test_lockf_exclusive(self):
161166
self.f = open(TESTFN, 'wb+')
162167
cmd = fcntl.LOCK_EX | fcntl.LOCK_NB
@@ -169,6 +174,7 @@ def test_lockf_exclusive(self):
169174
self.assertEqual(p.exitcode, 0)
170175

171176
@unittest.skipIf(platform.system() == "AIX", "AIX returns PermissionError")
177+
@requires_subprocess()
172178
def test_lockf_share(self):
173179
self.f = open(TESTFN, 'wb+')
174180
cmd = fcntl.LOCK_SH | fcntl.LOCK_NB

‎Lib/test/test_ftplib.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from unittest import TestCase, skipUnless
2020
from test import support
21+
from test.support import requires_subprocess
2122
from test.support import threading_helper
2223
from test.support import socket_helper
2324
from test.support import warnings_helper
@@ -900,6 +901,7 @@ def retr():
900901

901902

902903
@skipUnless(ssl, "SSL not available")
904+
@requires_subprocess()
903905
class TestTLS_FTPClassMixin(TestFTPClass):
904906
"""Repeat TestFTPClass tests starting the TLS layer for both control
905907
and data connections first.
@@ -916,6 +918,7 @@ def setUp(self, encoding=DEFAULT_ENCODING):
916918

917919

918920
@skipUnless(ssl, "SSL not available")
921+
@requires_subprocess()
919922
class TestTLS_FTPClass(TestCase):
920923
"""Specific TLS_FTP class tests."""
921924

‎Lib/test/test_genericpath.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import sys
88
import unittest
99
import warnings
10-
from test.support import is_emscripten
11-
from test.support import os_helper
12-
from test.support import warnings_helper
10+
from test.support import (
11+
is_apple, is_emscripten, os_helper, warnings_helper
12+
)
1313
from test.support.script_helper import assert_python_ok
1414
from test.support.os_helper import FakePath
1515

@@ -483,12 +483,16 @@ def test_abspath_issue3426(self):
483483
self.assertIsInstance(abspath(path), str)
484484

485485
def test_nonascii_abspath(self):
486-
if (os_helper.TESTFN_UNDECODABLE
487-
# macOS and Emscripten deny the creation of a directory with an
488-
# invalid UTF-8 name. Windows allows creating a directory with an
489-
# arbitrary bytes name, but fails to enter this directory
490-
# (when the bytes name is used).
491-
and sys.platform not in ('win32', 'darwin', 'emscripten', 'wasi')):
486+
if (
487+
os_helper.TESTFN_UNDECODABLE
488+
# Apple platforms and Emscripten/WASI deny the creation of a
489+
# directory with an invalid UTF-8 name. Windows allows creating a
490+
# directory with an arbitrary bytes name, but fails to enter this
491+
# directory (when the bytes name is used).
492+
and sys.platform not in {
493+
"win32", "emscripten", "wasi"
494+
} and not is_apple
495+
):
492496
name = os_helper.TESTFN_UNDECODABLE
493497
elif os_helper.TESTFN_NONASCII:
494498
name = os_helper.TESTFN_NONASCII

0 commit comments

Comments
 (0)
Please sign in to comment.