]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-90473: WASI: skip gethostname tests (GH-93092)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 23 May 2022 15:21:45 +0000 (08:21 -0700)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 15:21:45 +0000 (08:21 -0700)
- WASI's ``gethostname()`` is a stub that always fails with OSError
  ``ENOTSUP``
- skip mailcap ``test`` if subprocess is not available
- WASI process_time clock does not work.
(cherry picked from commit 760ec8940aabd6a7fc471bd913ea1ac501cc604b)

Co-authored-by: Christian Heimes <christian@python.org>
Lib/test/support/socket_helper.py
Lib/test/test_mailbox.py
Lib/test/test_mailcap.py
Lib/test/test_smtpd.py
Lib/test/test_support.py
Lib/test/test_time.py
Lib/test/test_urllib.py
Lib/test/test_urllib_response.py
Tools/wasm/README.md

index 754af181ec922ea2c0f620b28428d331237c2b5f..42b2a93398cbf731ca5b4ea16fcef079fbd02a21 100644 (file)
@@ -11,6 +11,9 @@ HOST = "localhost"
 HOSTv4 = "127.0.0.1"
 HOSTv6 = "::1"
 
+# WASI SDK 15.0 does not provide gethostname, stub raises OSError ENOTSUP.
+has_gethostname = not support.is_wasi
+
 
 def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
     """Returns an unused port that should be suitable for binding.  This is
index 20c460e300cc9de39e13bafc0b42f6a4f4e026a8..07c2764dfd1b2f598e09dee0d1158b252e431923 100644 (file)
@@ -10,12 +10,17 @@ import io
 import tempfile
 from test import support
 from test.support import os_helper
+from test.support import socket_helper
 import unittest
 import textwrap
 import mailbox
 import glob
 
 
+if not socket_helper.has_gethostname:
+    raise unittest.SkipTest("test requires gethostname()")
+
+
 class TestBase:
 
     all_mailbox_types = (mailbox.Message, mailbox.MaildirMessage,
index 97a8fac6e074adc8f57cba5af1f3dc13b5f6f9c8..d3995b14720e660bc585888ef19bd913116d5c87 100644 (file)
@@ -221,6 +221,10 @@ class FindmatchTest(unittest.TestCase):
 
     @unittest.skipUnless(os.name == "posix", "Requires 'test' command on system")
     @unittest.skipIf(sys.platform == "vxworks", "'test' command is not supported on VxWorks")
+    @unittest.skipUnless(
+        test.support.has_subprocess_support,
+        "'test' command needs process support."
+    )
     def test_test(self):
         # findmatch() will automatically check any "test" conditions and skip
         # the entry if the check fails.
index 57eb98ebc1d1efffa470639f00ba768f756b40d5..39ff8793648ba6474994bdc84f2cc1472224f71a 100644 (file)
@@ -10,6 +10,9 @@ import io
 smtpd = warnings_helper.import_deprecated('smtpd')
 asyncore = warnings_helper.import_deprecated('asyncore')
 
+if not socket_helper.has_gethostname:
+    raise unittest.SkipTest("test requires gethostname()")
+
 
 class DummyServer(smtpd.SMTPServer):
     def __init__(self, *args, **kwargs):
index 7a8b6819c5a91b37c42544f83094a1d880819f55..23bcceedd71b2a570c1a110b0d55b8885d3796d1 100644 (file)
@@ -664,6 +664,7 @@ class TestSupport(unittest.TestCase):
             self.assertTrue(support.match_test(test_chdir))
 
     @unittest.skipIf(support.is_emscripten, "Unstable in Emscripten")
+    @unittest.skipIf(support.is_wasi, "Unavailable on WASI")
     def test_fd_count(self):
         # We cannot test the absolute value of fd_count(): on old Linux
         # kernel or glibc versions, os.urandom() keeps a FD open on
index dc0bbb0ee2931156976c2ee6bdc4035bf6d2ab8b..884b14231f57375965e22b643804c2d11407c4ef 100644 (file)
@@ -489,6 +489,9 @@ class TimeTestCase(unittest.TestCase):
     def test_perf_counter(self):
         time.perf_counter()
 
+    @unittest.skipIf(
+        support.is_wasi, "process_time not available on WASI"
+    )
     def test_process_time(self):
         # process_time() should not include time spend during a sleep
         start = time.process_time()
index bc6e74c291ac1c0b72ec5f35a7c8872fed00b0bc..f067560ca6caa1eadc4d2b9884d58c0b114f6a55 100644 (file)
@@ -10,6 +10,7 @@ import unittest
 from unittest.mock import patch
 from test import support
 from test.support import os_helper
+from test.support import socket_helper
 from test.support import warnings_helper
 import os
 try:
@@ -24,6 +25,10 @@ from base64 import b64encode
 import collections
 
 
+if not socket_helper.has_gethostname:
+    raise unittest.SkipTest("test requires gethostname()")
+
+
 def hexescape(char):
     """Escape char as RFC 2396 specifies"""
     hex_repr = hex(ord(char))[2:].upper()
index 73d2ef0424f4af86c1c050d3601476f81b15d84a..b76763f4ed824f76ae8cf355fee46077d9438f7e 100644 (file)
@@ -4,6 +4,11 @@ import socket
 import tempfile
 import urllib.response
 import unittest
+from test import support
+
+if support.is_wasi:
+    raise unittest.SkipTest("Cannot create socket on WASI")
+
 
 class TestResponse(unittest.TestCase):
 
index 977b2bb2a8ab930ae1ebea7a23bacd92eb519d21..9e253bc878bd95c4d52c062cd9f5332d0495f256 100644 (file)
@@ -239,6 +239,7 @@ are:
   yet. A future version of WASI may provide a limited ``set_permissions`` API.
 - File locking (``fcntl``) is not available.
 - ``os.pipe()``, ``os.mkfifo()``, and ``os.mknod()`` are not supported.
+- ``process_time`` clock does not work.
 
 
 # Detect WebAssembly builds