[Python-checkins] bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-31791)

tiran webhook-mailer at python.org
Thu Mar 10 07:44:05 EST 2022


https://github.com/python/cpython/commit/de554d6e02228b840eb6bffaf7d406c0ef368d5f
commit: de554d6e02228b840eb6bffaf7d406c0ef368d5f
branch: main
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2022-03-10T13:43:40+01:00
summary:

bpo-40280: Skip more tests/features that don't apply to Emscripten (GH-31791)

- fd inheritance can't be modified because Emscripten doesn't support subprocesses anyway.
- setpriority always fails
- geteuid no longer causes problems with latest emsdk
- umask is a stub
- geteuid / getuid always return 0, but process cannot chown to random uid.

files:
M Lib/test/support/__init__.py
M Lib/test/test_os.py
M Lib/test/test_pathlib.py
M Lib/test/test_posix.py
M Lib/test/test_tarfile.py
M Tools/wasm/config.site-wasm32-emscripten

diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index d80472d8776f6..865fb976f532e 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -517,7 +517,7 @@ def requires_fork():
 has_subprocess_support = not is_emscripten and not is_wasi
 
 def requires_subprocess():
-    """Used for subprocess, os.spawn calls"""
+    """Used for subprocess, os.spawn calls, fd inheritance"""
     return unittest.skipUnless(has_subprocess_support, "requires subprocess support")
 
 
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index 4800291023233..ae8d930a95253 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -2192,6 +2192,7 @@ def test_write(self):
     def test_writev(self):
         self.check(os.writev, [b'abc'])
 
+    @support.requires_subprocess()
     def test_inheritable(self):
         self.check(os.get_inheritable)
         self.check(os.set_inheritable, True)
@@ -3866,6 +3867,8 @@ def test_cpu_count(self):
             self.skipTest("Could not determine the number of CPUs")
 
 
+# FD inheritance check is only useful for systems with process support.
+ at support.requires_subprocess()
 class FDInheritanceTests(unittest.TestCase):
     def test_get_set_inheritable(self):
         fd = os.open(__file__, os.O_RDONLY)
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 713d27908e756..66e44479239cf 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -13,6 +13,7 @@
 from unittest import mock
 
 from test.support import import_helper
+from test.support import is_emscripten
 from test.support import os_helper
 from test.support.os_helper import TESTFN, FakePath
 
@@ -2158,6 +2159,7 @@ def test_mkdir_exist_ok_with_parent(self):
         self.assertTrue(p.exists())
         self.assertEqual(p.stat().st_ctime, st_ctime_first)
 
+    @unittest.skipIf(is_emscripten, "FS root cannot be modified on Emscripten.")
     def test_mkdir_exist_ok_root(self):
         # Issue #25803: A drive root could raise PermissionError on Windows.
         self.cls('/').resolve().mkdir(exist_ok=True)
@@ -2342,6 +2344,9 @@ def test_is_socket_false(self):
         self.assertIs((P / 'fileA\x00').is_socket(), False)
 
     @unittest.skipUnless(hasattr(socket, "AF_UNIX"), "Unix sockets required")
+    @unittest.skipIf(
+        is_emscripten, "Unix sockets are not implemented on Emscripten."
+    )
     def test_is_socket_true(self):
         P = self.cls(BASE, 'mysock')
         sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -2497,6 +2502,9 @@ def _check_symlink_loop(self, *args, strict=True):
         with self.assertRaises(RuntimeError):
             print(path.resolve(strict))
 
+    @unittest.skipIf(
+        is_emscripten, "umask is not implemented on Emscripten."
+    )
     def test_open_mode(self):
         old_mask = os.umask(0)
         self.addCleanup(os.umask, old_mask)
@@ -2520,6 +2528,9 @@ def test_resolve_root(self):
         finally:
             os.chdir(current_directory)
 
+    @unittest.skipIf(
+        is_emscripten, "umask is not implemented on Emscripten."
+    )
     def test_touch_mode(self):
         old_mask = os.umask(0)
         self.addCleanup(os.umask, old_mask)
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index 395f065234519..c10039b17f7f8 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -30,8 +30,11 @@
 _DUMMY_SYMLINK = os.path.join(tempfile.gettempdir(),
                               os_helper.TESTFN + '-dummy-symlink')
 
-requires_32b = unittest.skipUnless(sys.maxsize < 2**32,
-        'test is only meaningful on 32-bit builds')
+requires_32b = unittest.skipUnless(
+    # Emscripten has 32 bits pointers, but support 64 bits syscall args.
+    sys.maxsize < 2**32 and not support.is_emscripten,
+    'test is only meaningful on 32-bit builds'
+)
 
 def _supports_sched():
     if not hasattr(posix, 'sched_getscheduler'):
@@ -578,6 +581,7 @@ def test_dup2(self):
 
     @unittest.skipUnless(hasattr(os, 'O_CLOEXEC'), "needs os.O_CLOEXEC")
     @support.requires_linux_version(2, 6, 23)
+    @support.requires_subprocess()
     def test_oscloexec(self):
         fd = os.open(os_helper.TESTFN, os.O_RDONLY|os.O_CLOEXEC)
         self.addCleanup(os.close, fd)
@@ -737,7 +741,11 @@ def check_stat(uid, gid):
             is_root = (uid in (0, 1))
         else:
             is_root = (uid == 0)
-        if is_root:
+        if support.is_emscripten:
+            # Emscripten getuid() / geteuid() always return 0 (root), but
+            # cannot chown uid/gid to random value.
+            pass
+        elif is_root:
             # Try an amusingly large uid/gid to make sure we handle
             # large unsigned values.  (chown lets you use any
             # uid/gid you like, even if they aren't defined.)
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 0a67bcb0b09d7..12850cd635e99 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1498,6 +1498,7 @@ def test_stream_padding(self):
 
     @unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
                          "Missing umask implementation")
+    @unittest.skipIf(support.is_emscripten, "Emscripten's umask is a stub.")
     def test_file_mode(self):
         # Test for issue #8464: Create files with correct
         # permissions.
diff --git a/Tools/wasm/config.site-wasm32-emscripten b/Tools/wasm/config.site-wasm32-emscripten
index f85024e21720f..5eaa7933776a8 100644
--- a/Tools/wasm/config.site-wasm32-emscripten
+++ b/Tools/wasm/config.site-wasm32-emscripten
@@ -62,6 +62,7 @@ ac_cv_func_pwritev2=no
 ac_cv_func_pwritev=no
 ac_cv_func_pipe2=no
 ac_cv_func_nice=no
+ac_cv_func_setpriority=no
 ac_cv_func_setitimer=no
 # unsupported syscall: __syscall_prlimit64
 ac_cv_func_prlimit=no
@@ -92,11 +93,6 @@ ac_cv_func_setgroups=no
 ac_cv_func_setresuid=no
 ac_cv_func_setresgid=no
 
-# Emscripten geteuid() / getegid() always return 0 (root), which breaks
-# assumption in tarfile module and some tests.
-ac_cv_func_getegid=no
-ac_cv_func_geteuid=no
-
 # Emscripten does not support hard links, always fails with errno 34
 # "Too many links". See emscripten_syscall_stubs.c
 ac_cv_func_link=no



More information about the Python-checkins mailing list