summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-02-05 19:52:01 (GMT)
committerGitHub <noreply@github.com>2022-02-05 19:52:01 (GMT)
commit96b344c2f15cb09251018f57f19643fe20637392 (patch)
tree3fe6c8f5d1a2897881806db1f3b441d11114adeb /Lib/test
parent9d4161a60ca8b470148ffd6c73e3110a0aa6d66f (diff)
downloadcpython-96b344c2f15cb09251018f57f19643fe20637392.zip
cpython-96b344c2f15cb09251018f57f19643fe20637392.tar.gz
cpython-96b344c2f15cb09251018f57f19643fe20637392.tar.bz2
bpo-40280: Address more test failures on Emscripten (GH-31050)
Co-authored-by: Brett Cannon <brett@python.org>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/support/__init__.py2
-rw-r--r--Lib/test/support/os_helper.py2
-rw-r--r--Lib/test/test_builtin.py2
-rw-r--r--Lib/test/test_capi.py2
-rw-r--r--Lib/test/test_faulthandler.py3
-rw-r--r--Lib/test/test_fileio.py4
-rw-r--r--Lib/test/test_genericalias.py17
-rw-r--r--Lib/test/test_getpass.py3
-rw-r--r--Lib/test/test_inspect.py1
-rw-r--r--Lib/test/test_interpreters.py3
-rw-r--r--Lib/test/test_io.py13
-rw-r--r--Lib/test/test_os.py4
-rw-r--r--Lib/test/test_posix.py9
-rw-r--r--Lib/test/test_pwd.py2
-rw-r--r--Lib/test/test_pyexpat.py7
-rw-r--r--Lib/test/test_resource.py1
-rw-r--r--Lib/test/test_zipfile.py8
17 files changed, 64 insertions, 19 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index e5eb66e..9d0d3d9 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -1278,6 +1278,8 @@ def reap_children():
# Need os.waitpid(-1, os.WNOHANG): Windows is not supported
if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):
return
+ elif not has_subprocess_support:
+ return
# Reap all our dead child processes so we don't leave zombies around.
# These hog resources and might be causing some of the buildbots to die.
diff --git a/Lib/test/support/os_helper.py b/Lib/test/support/os_helper.py
index 50aa7a7..c761d7b 100644
--- a/Lib/test/support/os_helper.py
+++ b/Lib/test/support/os_helper.py
@@ -502,7 +502,7 @@ class FakePath:
def fd_count():
"""Count the number of open file descriptors.
"""
- if sys.platform.startswith(('linux', 'freebsd')):
+ if sys.platform.startswith(('linux', 'freebsd', 'emscripten')):
try:
names = os.listdir("/proc/self/fd")
# Subtract one because listdir() internally opens a file
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
index c6e67cc..a601a52 100644
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -393,6 +393,7 @@ class BuiltinTest(unittest.TestCase):
msg=f"source={source} mode={mode}")
+ @unittest.skipIf(support.is_emscripten, "socket.accept is broken")
def test_compile_top_level_await(self):
"""Test whether code some top level await can be compiled.
@@ -1213,6 +1214,7 @@ class BuiltinTest(unittest.TestCase):
os.environ.clear()
os.environ.update(old_environ)
+ @support.requires_subprocess()
def test_open_non_inheritable(self):
fileobj = open(__file__, encoding="utf-8")
with fileobj:
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index ccf8ced..089088d 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -611,6 +611,7 @@ class CAPITest(unittest.TestCase):
self.assertNotIn(name, modules)
self.assertEqual(len(modules), total)
+ @support.requires_subprocess()
def test_fatal_error(self):
# By default, stdlib extension modules are ignored,
# but not test modules.
@@ -880,6 +881,7 @@ class Test_testinternalcapi(unittest.TestCase):
if name.startswith('test_'))
+@support.requires_subprocess()
class PyMemDebugTests(unittest.TestCase):
PYTHONMALLOC = 'debug'
# '0x04c06e0' or '04C06E0'
diff --git a/Lib/test/test_faulthandler.py b/Lib/test/test_faulthandler.py
index daacdee..8d106da 100644
--- a/Lib/test/test_faulthandler.py
+++ b/Lib/test/test_faulthandler.py
@@ -19,6 +19,9 @@ try:
except ImportError:
_testcapi = None
+if not support.has_subprocess_support:
+ raise unittest.SkipTest("test module requires subprocess")
+
TIMEOUT = 0.5
MS_WINDOWS = (os.name == 'nt')
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 4269b0e..e4984d3 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -9,7 +9,7 @@ from array import array
from weakref import proxy
from functools import wraps
-from test.support import cpython_only, swap_attr, gc_collect
+from test.support import cpython_only, swap_attr, gc_collect, is_emscripten
from test.support.os_helper import (TESTFN, TESTFN_UNICODE, make_bad_fd)
from test.support.warnings_helper import check_warnings
from collections import UserList
@@ -373,7 +373,7 @@ class OtherFileTests:
self.assertEqual(f.isatty(), False)
f.close()
- if sys.platform != "win32":
+ if sys.platform != "win32" and not is_emscripten:
try:
f = self.FileIO("/dev/tty", "a")
except OSError:
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 706cc5e..d311281 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -24,14 +24,20 @@ from filecmp import dircmp
from fileinput import FileInput
from itertools import chain
from http.cookies import Morsel
-from multiprocessing.managers import ValueProxy
-from multiprocessing.pool import ApplyResult
+try:
+ from multiprocessing.managers import ValueProxy
+ from multiprocessing.pool import ApplyResult
+ from multiprocessing.queues import SimpleQueue as MPSimpleQueue
+except ImportError:
+ # _multiprocessing module is optional
+ ValueProxy = None
+ ApplyResult = None
+ MPSimpleQueue = None
try:
from multiprocessing.shared_memory import ShareableList
except ImportError:
# multiprocessing.shared_memory is not available on e.g. Android
ShareableList = None
-from multiprocessing.queues import SimpleQueue as MPSimpleQueue
from os import DirEntry
from re import Pattern, Match
from types import GenericAlias, MappingProxyType, AsyncGeneratorType
@@ -79,13 +85,14 @@ class BaseTest(unittest.TestCase):
Queue, SimpleQueue,
_AssertRaisesContext,
SplitResult, ParseResult,
- ValueProxy, ApplyResult,
WeakSet, ReferenceType, ref,
- ShareableList, MPSimpleQueue,
+ ShareableList,
Future, _WorkItem,
Morsel]
if ctypes is not None:
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
+ if ValueProxy is not None:
+ generic_types.extend((ValueProxy, ApplyResult, MPSimpleQueue))
def test_subscriptable(self):
for t in self.generic_types:
diff --git a/Lib/test/test_getpass.py b/Lib/test/test_getpass.py
index 3452e46..98ecec9 100644
--- a/Lib/test/test_getpass.py
+++ b/Lib/test/test_getpass.py
@@ -28,6 +28,9 @@ class GetpassGetuserTest(unittest.TestCase):
getpass.getuser()
except ImportError: # in case there's no pwd module
pass
+ except KeyError:
+ # current user has no pwd entry
+ pass
self.assertEqual(
environ.get.call_args_list,
[mock.call(x) for x in ('LOGNAME', 'USER', 'LNAME', 'USERNAME')])
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index a553431..29589a7 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -788,6 +788,7 @@ class TestBuggyCases(GetSourceBase):
self.assertSourceEqual(mod2.cls213, 218, 222)
self.assertSourceEqual(mod2.cls213().func219(), 220, 221)
+ @unittest.skipIf(support.is_emscripten, "socket.accept is broken")
def test_nested_class_definition_inside_async_function(self):
import asyncio
self.addCleanup(asyncio.set_event_loop_policy, None)
diff --git a/Lib/test/test_interpreters.py b/Lib/test/test_interpreters.py
index 6266aa7..48c7119 100644
--- a/Lib/test/test_interpreters.py
+++ b/Lib/test/test_interpreters.py
@@ -5,7 +5,8 @@ from textwrap import dedent
import unittest
import time
-import _xxsubinterpreters as _interpreters
+from test.support import import_helper
+_interpreters = import_helper.import_module('_xxsubinterpreters')
from test.support import interpreters
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index a10611a..e9abd15 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -76,6 +76,10 @@ def _default_chunk_size():
with open(__file__, "r", encoding="latin-1") as f:
return f._CHUNK_SIZE
+requires_alarm = unittest.skipUnless(
+ hasattr(signal, "alarm"), "test requires signal.alarm()"
+)
+
class MockRawIOWithoutRead:
"""A RawIO implementation without read(), so as to exercise the default
@@ -4435,12 +4439,15 @@ class SignalsTest(unittest.TestCase):
if e.errno != errno.EBADF:
raise
+ @requires_alarm
def test_interrupted_write_unbuffered(self):
self.check_interrupted_write(b"xy", b"xy", mode="wb", buffering=0)
+ @requires_alarm
def test_interrupted_write_buffered(self):
self.check_interrupted_write(b"xy", b"xy", mode="wb")
+ @requires_alarm
def test_interrupted_write_text(self):
self.check_interrupted_write("xy", b"xy", mode="w", encoding="ascii")
@@ -4472,9 +4479,11 @@ class SignalsTest(unittest.TestCase):
wio.close()
os.close(r)
+ @requires_alarm
def test_reentrant_write_buffered(self):
self.check_reentrant_write(b"xy", mode="wb")
+ @requires_alarm
def test_reentrant_write_text(self):
self.check_reentrant_write("xy", mode="w", encoding="ascii")
@@ -4502,10 +4511,12 @@ class SignalsTest(unittest.TestCase):
os.close(w)
os.close(r)
+ @requires_alarm
def test_interrupted_read_retry_buffered(self):
self.check_interrupted_read_retry(lambda x: x.decode('latin1'),
mode="rb")
+ @requires_alarm
def test_interrupted_read_retry_text(self):
self.check_interrupted_read_retry(lambda x: x,
mode="r", encoding="latin1")
@@ -4578,9 +4589,11 @@ class SignalsTest(unittest.TestCase):
if e.errno != errno.EBADF:
raise
+ @requires_alarm
def test_interrupted_write_retry_buffered(self):
self.check_interrupted_write_retry(b"x", mode="wb")
+ @requires_alarm
def test_interrupted_write_retry_text(self):
self.check_interrupted_write_retry("x", mode="w", encoding="latin1")
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 84c27f3..6606915 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -992,6 +992,7 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
@unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
'requires a shell')
@unittest.skipUnless(hasattr(os, 'popen'), "needs os.popen()")
+ @support.requires_subprocess()
def test_update2(self):
os.environ.clear()
os.environ.update(HELLO="World")
@@ -1002,6 +1003,7 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
@unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
'requires a shell')
@unittest.skipUnless(hasattr(os, 'popen'), "needs os.popen()")
+ @support.requires_subprocess()
def test_os_popen_iter(self):
with os.popen("%s -c 'echo \"line1\nline2\nline3\"'"
% unix_shell) as popen:
@@ -1173,6 +1175,8 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
def _test_underlying_process_env(self, var, expected):
if not (unix_shell and os.path.exists(unix_shell)):
return
+ elif not support.has_subprocess_support:
+ return
with os.popen(f"{unix_shell} -c 'echo ${var}'") as popen:
value = popen.read().strip()
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 974edd7..5cc04fd 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -184,7 +184,7 @@ class PosixTester(unittest.TestCase):
posix.truncate(os_helper.TESTFN, 0)
@unittest.skipUnless(getattr(os, 'execve', None) in os.supports_fd, "test needs execve() to support the fd parameter")
- @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
+ @support.requires_fork()
def test_fexecve(self):
fp = os.open(sys.executable, os.O_RDONLY)
try:
@@ -199,7 +199,7 @@ class PosixTester(unittest.TestCase):
@unittest.skipUnless(hasattr(posix, 'waitid'), "test needs posix.waitid()")
- @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
+ @support.requires_fork()
def test_waitid(self):
pid = os.fork()
if pid == 0:
@@ -209,7 +209,7 @@ class PosixTester(unittest.TestCase):
res = posix.waitid(posix.P_PID, pid, posix.WEXITED)
self.assertEqual(pid, res.si_pid)
- @unittest.skipUnless(hasattr(os, 'fork'), "test needs os.fork()")
+ @support.requires_fork()
def test_register_at_fork(self):
with self.assertRaises(TypeError, msg="Positional args not allowed"):
os.register_at_fork(lambda: None)
@@ -1056,6 +1056,7 @@ class PosixTester(unittest.TestCase):
@unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()")
@unittest.skipUnless(hasattr(os, 'popen'), "test needs os.popen()")
+ @support.requires_subprocess()
def test_getgroups(self):
with os.popen('id -G 2>/dev/null') as idg:
groups = idg.read().strip()
@@ -1481,7 +1482,7 @@ class TestPosixDirFd(unittest.TestCase):
self.addCleanup(posix.unlink, fullname)
raise
- @unittest.skipUnless(os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
+ @unittest.skipUnless(hasattr(os, 'mkfifo') and os.mkfifo in os.supports_dir_fd, "test needs dir_fd support in os.mkfifo()")
def test_mkfifo_dir_fd(self):
with self.prepare() as (dir_fd, name, fullname):
try:
diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py
index f8f1257..c789326 100644
--- a/Lib/test/test_pwd.py
+++ b/Lib/test/test_pwd.py
@@ -69,7 +69,7 @@ class PwdTest(unittest.TestCase):
allnames = list(bynames.keys())
namei = 0
- fakename = allnames[namei]
+ fakename = allnames[namei] if allnames else "invaliduser"
while fakename in bynames:
chars = list(fakename)
for i in range(len(chars)):
diff --git a/Lib/test/test_pyexpat.py b/Lib/test/test_pyexpat.py
index b2b4dea..6e57845 100644
--- a/Lib/test/test_pyexpat.py
+++ b/Lib/test/test_pyexpat.py
@@ -12,7 +12,7 @@ import traceback
from xml.parsers import expat
from xml.parsers.expat import errors
-from test.support import sortdict
+from test.support import sortdict, is_emscripten
class SetAttributeTest(unittest.TestCase):
@@ -466,7 +466,10 @@ class HandlerExceptionTest(unittest.TestCase):
"pyexpat.c", "StartElement")
self.check_traceback_entry(entries[2],
"test_pyexpat.py", "StartElementHandler")
- if sysconfig.is_python_build() and not (sys.platform == 'win32' and platform.machine() == 'ARM'):
+ if (sysconfig.is_python_build()
+ and not (sys.platform == 'win32' and platform.machine() == 'ARM')
+ and not is_emscripten
+ ):
self.assertIn('call_with_frame("StartElement"', entries[1][3])
diff --git a/Lib/test/test_resource.py b/Lib/test/test_resource.py
index f2642c6..317e7ca 100644
--- a/Lib/test/test_resource.py
+++ b/Lib/test/test_resource.py
@@ -98,6 +98,7 @@ class ResourceTest(unittest.TestCase):
except (OverflowError, ValueError):
pass
+ @unittest.skipUnless(hasattr(resource, "getrusage"), "needs getrusage")
def test_getrusage(self):
self.assertRaises(TypeError, resource.getrusage)
self.assertRaises(TypeError, resource.getrusage, 42, 42)
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py
index e226dd7..de2dd33 100644
--- a/Lib/test/test_zipfile.py
+++ b/Lib/test/test_zipfile.py
@@ -22,7 +22,9 @@ from random import randint, random, randbytes
from test.support import script_helper
from test.support import (findfile, requires_zlib, requires_bz2,
requires_lzma, captured_stdout, requires_subprocess)
-from test.support.os_helper import TESTFN, unlink, rmtree, temp_dir, temp_cwd
+from test.support.os_helper import (
+ TESTFN, unlink, rmtree, temp_dir, temp_cwd, fd_count
+)
TESTFN2 = TESTFN + "2"
@@ -2539,14 +2541,14 @@ class TestsWithMultipleOpens(unittest.TestCase):
def test_many_opens(self):
# Verify that read() and open() promptly close the file descriptor,
# and don't rely on the garbage collector to free resources.
+ startcount = fd_count()
self.make_test_archive(TESTFN2)
with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
for x in range(100):
zipf.read('ones')
with zipf.open('ones') as zopen1:
pass
- with open(os.devnull, "rb") as f:
- self.assertLess(f.fileno(), 100)
+ self.assertEqual(startcount, fd_count())
def test_write_while_reading(self):
with zipfile.ZipFile(TESTFN2, 'w', zipfile.ZIP_DEFLATED) as zipf: