diff options
author | Christian Heimes <christian@python.org> | 2022-05-19 10:43:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 10:43:16 (GMT) |
commit | 137fd3d88aa46669f5717734e823f4c594ab2843 (patch) | |
tree | a527865e1f3729ef3d7c69a43d08072d8d837d9c /Lib/test | |
parent | e48ac9c1003c3816198cbfb6132a995150f9b048 (diff) | |
download | cpython-137fd3d88aa46669f5717734e823f4c594ab2843.zip cpython-137fd3d88aa46669f5717734e823f4c594ab2843.tar.gz cpython-137fd3d88aa46669f5717734e823f4c594ab2843.tar.bz2 |
gh-90473: Decrease recursion limit and skip tests on WASI (GH-92803)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pythoninfo.py | 10 | ||||
-rw-r--r-- | Lib/test/support/__init__.py | 5 | ||||
-rw-r--r-- | Lib/test/test_compile.py | 4 | ||||
-rw-r--r-- | Lib/test/test_fileio.py | 5 | ||||
-rw-r--r-- | Lib/test/test_largefile.py | 2 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 2 | ||||
-rw-r--r-- | Lib/test/test_os.py | 9 | ||||
-rw-r--r-- | Lib/test/test_signal.py | 6 | ||||
-rw-r--r-- | Lib/test/test_tomllib/test_misc.py | 7 | ||||
-rw-r--r-- | Lib/test/test_zipimport.py | 1 |
10 files changed, 43 insertions, 8 deletions
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py index 28549a6..84e1c04 100644 --- a/Lib/test/pythoninfo.py +++ b/Lib/test/pythoninfo.py @@ -545,8 +545,14 @@ def collect_ssl(info_add): def collect_socket(info_add): import socket - hostname = socket.gethostname() - info_add('socket.hostname', hostname) + try: + hostname = socket.gethostname() + except OSError: + # WASI SDK 15.0 does not have gethostname(2). + if sys.platform != "wasi": + raise + else: + info_add('socket.hostname', hostname) def collect_sqlite(info_add): diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index e4bda94..c284fc6 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -199,6 +199,11 @@ def get_original_stdout(): def _force_run(path, func, *args): try: return func(*args) + except FileNotFoundError as err: + # chmod() won't fix a missing file. + if verbose >= 2: + print('%s: %s' % (err.__class__.__name__, err)) + raise except OSError as err: if verbose >= 2: print('%s: %s' % (err.__class__.__name__, err)) diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 487a4fa..d435724 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -109,7 +109,9 @@ class TestSpecifics(unittest.TestCase): self.assertEqual(d['z'], 12) def test_extended_arg(self): - longexpr = 'x = x or ' + '-x' * 2500 + # default: 1000 * 2.5 = 2500 repetitions + repeat = int(sys.getrecursionlimit() * 2.5) + longexpr = 'x = x or ' + '-x' * repeat g = {} code = ''' def f(x): diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index e4984d3..c26cdc02 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -9,7 +9,9 @@ from array import array from weakref import proxy from functools import wraps -from test.support import cpython_only, swap_attr, gc_collect, is_emscripten +from test.support import ( + cpython_only, swap_attr, gc_collect, is_emscripten, is_wasi +) from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd) from test.support.warnings_helper import check_warnings from collections import UserList @@ -65,6 +67,7 @@ class AutoFileTests: self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops') + @unittest.skipIf(is_wasi, "WASI does not expose st_blksize.") def testBlksize(self): # test private _blksize attribute blksize = io.DEFAULT_BUFFER_SIZE diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index 8f6bec1..3c11c59 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -156,6 +156,8 @@ class TestFileMethods(LargeFileTest): def skip_no_disk_space(path, required): def decorator(fun): def wrapper(*args, **kwargs): + if not hasattr(shutil, "disk_usage"): + raise unittest.SkipTest("requires shutil.disk_usage") if shutil.disk_usage(os.path.realpath(path)).free < required: hsize = int(required / 1024 / 1024) raise unittest.SkipTest( diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index e69afae..fd56232 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -5280,6 +5280,7 @@ class FileHandlerTest(BaseFileTest): self.assertEqual(fp.read().strip(), '1') class RotatingFileHandlerTest(BaseFileTest): + @unittest.skipIf(support.is_wasi, "WASI does not have /dev/null.") def test_should_not_rollover(self): # If maxbytes is zero rollover never occurs rh = logging.handlers.RotatingFileHandler( @@ -5387,6 +5388,7 @@ class RotatingFileHandlerTest(BaseFileTest): rh.close() class TimedRotatingFileHandlerTest(BaseFileTest): + @unittest.skipIf(support.is_wasi, "WASI does not have /dev/null.") def test_should_not_rollover(self): # See bpo-45401. Should only ever rollover regular files fh = logging.handlers.TimedRotatingFileHandler( diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index 36ad587..ae07182 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -11,7 +11,6 @@ import fnmatch import fractions import itertools import locale -import mmap import os import pickle import select @@ -59,6 +58,10 @@ try: except ImportError: INT_MAX = PY_SSIZE_T_MAX = sys.maxsize +try: + import mmap +except ImportError: + mmap = None from test.support.script_helper import assert_python_ok from test.support import unix_shell @@ -2167,7 +2170,8 @@ class TestInvalidFD(unittest.TestCase): @unittest.skipUnless(hasattr(os, 'fpathconf'), 'test needs os.fpathconf()') @unittest.skipIf( - support.is_emscripten, "musl libc issue on Emscripten, bpo-46390" + support.is_emscripten or support.is_wasi, + "musl libc issue on Emscripten/WASI, bpo-46390" ) def test_fpathconf(self): self.check(os.pathconf, "PC_NAME_MAX") @@ -2460,6 +2464,7 @@ class Win32KillTests(unittest.TestCase): # os.kill on Windows can take an int which gets set as the exit code self._kill(100) + @unittest.skipIf(mmap is None, "requires mmap") def _kill_with_event(self, event, name): tagname = "test_os_%s" % uuid.uuid1() m = mmap.mmap(-1, 1, tagname) diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 6d3b299..6aa529b 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -107,6 +107,10 @@ class PosixTests(unittest.TestCase): script = os.path.join(dirname, 'signalinterproctester.py') assert_python_ok(script) + @unittest.skipUnless( + hasattr(signal, "valid_signals"), + "requires signal.valid_signals" + ) def test_valid_signals(self): s = signal.valid_signals() self.assertIsInstance(s, set) @@ -212,6 +216,7 @@ class WakeupFDTests(unittest.TestCase): self.assertRaises((ValueError, OSError), signal.set_wakeup_fd, fd) + @unittest.skipUnless(support.has_socket_support, "needs working sockets.") def test_invalid_socket(self): sock = socket.socket() fd = sock.fileno() @@ -241,6 +246,7 @@ class WakeupFDTests(unittest.TestCase): self.assertEqual(signal.set_wakeup_fd(-1), -1) @unittest.skipIf(support.is_emscripten, "Emscripten cannot fstat pipes.") + @unittest.skipUnless(support.has_socket_support, "needs working sockets.") def test_set_wakeup_fd_socket_result(self): sock1 = socket.socket() self.addCleanup(sock1.close) diff --git a/Lib/test/test_tomllib/test_misc.py b/Lib/test/test_tomllib/test_misc.py index 76fa590..378db58 100644 --- a/Lib/test/test_tomllib/test_misc.py +++ b/Lib/test/test_tomllib/test_misc.py @@ -6,6 +6,7 @@ import copy import datetime from decimal import Decimal as D from pathlib import Path +import sys import tempfile import unittest @@ -91,11 +92,13 @@ class TestMiscellaneous(unittest.TestCase): self.assertEqual(obj_copy, expected_obj) def test_inline_array_recursion_limit(self): - nest_count = 470 + # 470 with default recursion limit + nest_count = int(sys.getrecursionlimit() * 0.47) recursive_array_toml = "arr = " + nest_count * "[" + nest_count * "]" tomllib.loads(recursive_array_toml) def test_inline_table_recursion_limit(self): - nest_count = 310 + # 310 with default recursion limit + nest_count = int(sys.getrecursionlimit() * 0.31) recursive_table_toml = nest_count * "key = {" + nest_count * "}" tomllib.loads(recursive_table_toml) diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py index 85dbf4d..6678926 100644 --- a/Lib/test/test_zipimport.py +++ b/Lib/test/test_zipimport.py @@ -804,6 +804,7 @@ class BadFileZipImportTestCase(unittest.TestCase): os_helper.create_empty_file(TESTMOD) self.assertZipFailure(TESTMOD) + @unittest.skipIf(support.is_wasi, "mode 000 not supported.") def testFileUnreadable(self): os_helper.unlink(TESTMOD) fd = os.open(TESTMOD, os.O_CREAT, 000) |