8000 Add test exclusions to support running the test suite on iOS. · python/cpython@3f83f4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f83f4c

Browse files
committed
Add test exclusions to support running the test suite on iOS.
1 parent ff8939e commit 3f83f4c

31 files changed

+209
-145
lines changed

Lib/test/support/__init__.py

Lines changed: 18 additions & 4 deletions
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,12 +532,26 @@ 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 = (
541+
hasattr(os, "fork")
542+
and not is_emscripten
543+
and not is_wasi
544+
and not is_apple_mobile
545+
)
536546

537547
def requires_fork():
538548
return unittest.skipUnless(has_fork_support, "requires working os.fork()")
539549

540-
has_subprocess_support = not is_emscripten and not is_wasi
550+
has_subprocess_support = (
551+
not is_emscripten
552+
and not is_wasi
553+
and not is_apple_mobile
554+
)
541555

542556
def requires_subprocess():
543557
"""Used for subprocess, os.spawn calls, fd inheritance"""

Lib/test/support/os_helper.py

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ async def test():
17991799
next(it)
18001800

18011801

1802+
@support.requires_subprocess()
18021803
class SubprocessTestsMixin:
18031804

18041805
def check_terminated(self, returncode):

Lib/test/test_asyncio/test_streams.py

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,6 +1875,7 @@ async def runner():
18751875

18761876

18771877
@unittest.skipUnless(hasattr(os, 'fork'), 'requires os.fork()')
1878+
@support.requires_subprocess()
18781879
class TestFork(unittest.IsolatedAsyncioTestCase):
18791880

18801881
async def test_fork_not_share_event_loop(self):

Lib/test/test_cmd_line_script.py

Lines changed: 10 additions & 6 deletions
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"Test InteractiveConsole and InteractiveInterpreter from code module"
2+
import site
23
import sys
34
import unittest
45
from textwrap import dedent
@@ -160,6 +161,10 @@ def setUp(self):
160161
self.console = code.InteractiveConsole(local_exit=True)
161162
self.mock_sys()
162163

164+
@unittest.skipif(
165+
site.USER_SITE is None,
166+
"exit() isn't defined unless there's a site module"
167+
)
163168
def test_exit(self):
164169
# default exit message
165170
self.infunc.side_effect = ["exit()"]

Lib/test/test_fcntl.py

Lines changed: 9 additions & 3 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 13 additions & 9 deletions
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

Lib/test/test_httpservers.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
import unittest
3232
from test import support
33-
from test.support import os_helper
34-
from test.support import threading_helper
33+
from test.support import (
34+
is_apple, os_helper, requires_subprocess, threading_helper
35+
)
3536

3637
support.requires_working_socket(module=True)
3738

@@ -410,8 +411,8 @@ def close_conn():
410411
reader.close()
411412
return body
412413

413-
@unittest.skipIf(sys.platform == 'darwin',
414-
'undecodable name cannot always be decoded on macOS')
414+
@unittest.skipIf(is_apple,
415+
'undecodable name cannot always be decoded on Apple platforms')
415416
@unittest.skipIf(sys.platform == 'win32',
416417
'undecodable name cannot be decoded on win32')
417418
@unittest.skipUnless(os_helper.TESTFN_UNDECODABLE,
@@ -422,11 +423,11 @@ def test_undecodable_filename(self):
422423
with open(os.path.join(self.tempdir, filename), 'wb') as f:
423424
f.write(os_helper.TESTFN_UNDECODABLE)
424425
response = self.request(self.base_url + '/')
425-
if sys.platform == 'darwin':
426-
# On Mac OS the HFS+ filesystem replaces bytes that aren't valid
427-
# UTF-8 into a percent-encoded value.
426+
if is_apple:
427+
# On Apple platforms the HFS+ filesystem replaces bytes that
428+
# aren't valid UTF-8 into a percent-encoded value.
428429
for name in os.listdir(self.tempdir):
429-
if name != 'test': # Ignore a filename created in setUp().
430+
if name != 'test': # Ignore a filename created in setUp().
430431
filename = name
431432
break
432433
body = self.check_status_and_reason(response, HTTPStatus.OK)
@@ -697,6 +698,7 @@ def test_html_escape_filename(self):
697698

698699
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
699700
"This test can't be run reliably as root (issue #13308).")
701+
@requires_subprocess()
700702
class CGIHTTPServerTestCase(BaseTestCase):
701703
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
702704
_test_case_self = None # populated by each setUp() method call.

Lib/test/test_io.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@
3939
from test import support
4040
from test.support.script_helper import (
4141
assert_python_ok, assert_python_failure, run_python_until_end)
42-
from test.support import import_helper
43-
from test.support import os_helper
44-
from test.support import threading_helper
45-
from test.support import warnings_helper
46-
from test.support import skip_if_sanitizer
42+
from test.support import (
43+
import_helper, is_apple, os_helper, skip_if_sanitizer, threading_helper, warnings_helper
44+
)
4745
from test.support.os_helper import FakePath
4846

4947
import codecs
@@ -606,10 +604,10 @@ def test_raw_bytes_io(self):
606604
self.read_ops(f, True)
607605

608606
def test_large_file_ops(self):
609-
# On Windows and Mac OSX this test consumes large resources; It takes
610-
# a long time to build the >2 GiB file and takes >2 GiB of disk space
611-
# therefore the resource must be enabled to run this test.
612-
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
607+
# On Windows and Apple platforms this test consumes large resources; It
608+
# takes a long time to build the >2 GiB file and takes >2 GiB of disk
609+
# space therefore the resource must be enabled to run this test.
610+
if sys.platform[:3] == 'win' or is_apple:
613611
support.requires(
614612
'largefile',
615613
'test requires %s bytes and a long time to run' % self.LARGE)

Lib/test/test_marshal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from test import support
2-
from test.support import os_helper, requires_debug_ranges
2+
from test.support import is_apple_mobile, os_helper, requires_debug_ranges
33
from test.support.script_helper import assert_python_ok
44
import array
55
import io
@@ -286,7 +286,7 @@ def test_recursion_limit(self):
286286
#if os.name == 'nt' and support.Py_DEBUG:
287287
if os.name == 'nt':
288288
MAX_MARSHAL_STACK_DEPTH = 1000
289-
elif sys.platform == 'wasi':
289+
elif sys.platform == 'wasi' or is_apple_mobile:
290290
MAX_MARSHAL_STACK_DEPTH = 1500
291291
else:
292292
MAX_MARSHAL_STACK_DEPTH = 2000

Lib/test/test_mmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from test.support import (
2-
requires, _2G, _4G, gc_collect, cpython_only, is_emscripten
2+
requires, _2G, _4G, gc_collect, cpython_only, is_emscripten, is_apple,
33
)
44
from test.support.import_helper import import_module
55
from test.support.os_helper import TESTFN, unlink
@@ -1067,7 +1067,7 @@ def tearDown(self):
10671067
unlink(TESTFN)
10681068

10691069
def _make_test_file(self, num_zeroes, tail):
1070-
if sys.platform[:3] == 'win' or sys.platform == 'darwin':
1070+
if sys.platform[:3] == 'win' or is_apple:
10711071
requires('largefile',
10721072
'test requires %s bytes and a long time to run' % str(0x180000000))
10731073
f = open(TESTFN, 'w+b')

0 commit comments

Comments
 (0)
0