mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
gh-90473: Misc test fixes for WASI (GH-93218)
* ``sys.executable`` is not set
* WASI does not support subprocess
* ``pwd`` module is not available
* WASI checks ``open`` syscall flags more strict, needs r, w, rw flag.
* ``umask`` is not available
* ``/dev/null`` may not be accessible
(cherry picked from commit 1f134e96ba
)
Co-authored-by: Christian Heimes <christian@python.org>
This commit is contained in:
parent
307dacd651
commit
0fb70ce191
8 changed files with 26 additions and 7 deletions
|
@ -12,6 +12,7 @@ class BuildTestCase(support.TempdirManager,
|
||||||
support.LoggingSilencer,
|
support.LoggingSilencer,
|
||||||
unittest.TestCase):
|
unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skipUnless(sys.executable, "test requires sys.executable")
|
||||||
def test_finalize_options(self):
|
def test_finalize_options(self):
|
||||||
pkg_dir, dist = self.create_dist()
|
pkg_dir, dist = self.create_dist()
|
||||||
cmd = build(dist)
|
cmd = build(dist)
|
||||||
|
|
|
@ -63,7 +63,7 @@ class TestPgen2Caching(support.TestCase):
|
||||||
|
|
||||||
@unittest.skipIf(sys.executable is None, 'sys.executable required')
|
@unittest.skipIf(sys.executable is None, 'sys.executable required')
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
sys.platform == 'emscripten', 'requires working subprocess'
|
sys.platform in {'emscripten', 'wasi'}, 'requires working subprocess'
|
||||||
)
|
)
|
||||||
def test_load_grammar_from_subprocess(self):
|
def test_load_grammar_from_subprocess(self):
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import netrc, os, unittest, sys, textwrap
|
import netrc, os, unittest, sys, textwrap
|
||||||
from test.support import os_helper, run_unittest
|
from test.support import os_helper, run_unittest
|
||||||
|
|
||||||
|
try:
|
||||||
|
import pwd
|
||||||
|
except ImportError:
|
||||||
|
pwd = None
|
||||||
|
|
||||||
temp_filename = os_helper.TESTFN
|
temp_filename = os_helper.TESTFN
|
||||||
|
|
||||||
class NetrcTestCase(unittest.TestCase):
|
class NetrcTestCase(unittest.TestCase):
|
||||||
|
@ -266,6 +271,7 @@ class NetrcTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(os.name == 'posix', 'POSIX only test')
|
@unittest.skipUnless(os.name == 'posix', 'POSIX only test')
|
||||||
|
@unittest.skipIf(pwd is None, 'security check requires pwd module')
|
||||||
def test_security(self):
|
def test_security(self):
|
||||||
# This test is incomplete since we are normally not run as root and
|
# This test is incomplete since we are normally not run as root and
|
||||||
# therefore can't test the file ownership being wrong.
|
# therefore can't test the file ownership being wrong.
|
||||||
|
|
|
@ -1765,6 +1765,7 @@ class RemoveDirsTests(unittest.TestCase):
|
||||||
self.assertTrue(os.path.exists(os_helper.TESTFN))
|
self.assertTrue(os.path.exists(os_helper.TESTFN))
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(support.is_wasi, "WASI has no /dev/null")
|
||||||
class DevNullTests(unittest.TestCase):
|
class DevNullTests(unittest.TestCase):
|
||||||
def test_devnull(self):
|
def test_devnull(self):
|
||||||
with open(os.devnull, 'wb', 0) as f:
|
with open(os.devnull, 'wb', 0) as f:
|
||||||
|
@ -2111,6 +2112,7 @@ class Win32ErrorTests(unittest.TestCase):
|
||||||
self.assertRaises(OSError, os.chmod, os_helper.TESTFN, 0)
|
self.assertRaises(OSError, os.chmod, os_helper.TESTFN, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(support.is_wasi, "Cannot create invalid FD on WASI.")
|
||||||
class TestInvalidFD(unittest.TestCase):
|
class TestInvalidFD(unittest.TestCase):
|
||||||
singles = ["fchdir", "dup", "fdatasync", "fstat",
|
singles = ["fchdir", "dup", "fdatasync", "fstat",
|
||||||
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
|
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]
|
||||||
|
|
|
@ -13,7 +13,7 @@ import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from test.support import import_helper
|
from test.support import import_helper
|
||||||
from test.support import is_emscripten
|
from test.support import is_emscripten, is_wasi
|
||||||
from test.support import os_helper
|
from test.support import os_helper
|
||||||
from test.support.os_helper import TESTFN, FakePath
|
from test.support.os_helper import TESTFN, FakePath
|
||||||
|
|
||||||
|
@ -1530,6 +1530,7 @@ class _BasePathTest(object):
|
||||||
p = self.cls('')
|
p = self.cls('')
|
||||||
self.assertEqual(p.stat(), os.stat('.'))
|
self.assertEqual(p.stat(), os.stat('.'))
|
||||||
|
|
||||||
|
@unittest.skipIf(is_wasi, "WASI has no user accounts.")
|
||||||
def test_expanduser_common(self):
|
def test_expanduser_common(self):
|
||||||
P = self.cls
|
P = self.cls
|
||||||
p = P('~')
|
p = P('~')
|
||||||
|
@ -2530,7 +2531,8 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
|
||||||
print(path.resolve(strict))
|
print(path.resolve(strict))
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
is_emscripten, "umask is not implemented on Emscripten."
|
is_emscripten or is_wasi,
|
||||||
|
"umask is not implemented on Emscripten/WASI."
|
||||||
)
|
)
|
||||||
def test_open_mode(self):
|
def test_open_mode(self):
|
||||||
old_mask = os.umask(0)
|
old_mask = os.umask(0)
|
||||||
|
@ -2556,7 +2558,8 @@ class PosixPathTest(_BasePathTest, unittest.TestCase):
|
||||||
os.chdir(current_directory)
|
os.chdir(current_directory)
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipIf(
|
||||||
is_emscripten, "umask is not implemented on Emscripten."
|
is_emscripten or is_wasi,
|
||||||
|
"umask is not implemented on Emscripten/WASI."
|
||||||
)
|
)
|
||||||
def test_touch_mode(self):
|
def test_touch_mode(self):
|
||||||
old_mask = os.umask(0)
|
old_mask = os.umask(0)
|
||||||
|
|
|
@ -1498,7 +1498,10 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
|
@unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
|
||||||
"Missing umask implementation")
|
"Missing umask implementation")
|
||||||
@unittest.skipIf(support.is_emscripten, "Emscripten's umask is a stub.")
|
@unittest.skipIf(
|
||||||
|
support.is_emscripten or support.is_wasi,
|
||||||
|
"Emscripten's/WASI's umask is a stub."
|
||||||
|
)
|
||||||
def test_file_mode(self):
|
def test_file_mode(self):
|
||||||
# Test for issue #8464: Create files with correct
|
# Test for issue #8464: Create files with correct
|
||||||
# permissions.
|
# permissions.
|
||||||
|
|
|
@ -110,7 +110,7 @@ class TestUnicodeFiles(unittest.TestCase):
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
self.assertTrue(not os.path.exists(filename))
|
self.assertTrue(not os.path.exists(filename))
|
||||||
# and again with os.open.
|
# and again with os.open.
|
||||||
f = os.open(filename, os.O_CREAT)
|
f = os.open(filename, os.O_CREAT | os.O_WRONLY)
|
||||||
os.close(f)
|
os.close(f)
|
||||||
try:
|
try:
|
||||||
self._do_single(filename)
|
self._do_single(filename)
|
||||||
|
|
|
@ -239,7 +239,11 @@ are:
|
||||||
yet. A future version of WASI may provide a limited ``set_permissions`` API.
|
yet. A future version of WASI may provide a limited ``set_permissions`` API.
|
||||||
- File locking (``fcntl``) is not available.
|
- File locking (``fcntl``) is not available.
|
||||||
- ``os.pipe()``, ``os.mkfifo()``, and ``os.mknod()`` are not supported.
|
- ``os.pipe()``, ``os.mkfifo()``, and ``os.mknod()`` are not supported.
|
||||||
- ``process_time`` clock does not work.
|
- ``process_time`` does not work as expected because it's implemented using
|
||||||
|
wall clock.
|
||||||
|
- ``os.umask`` is a stub.
|
||||||
|
- ``sys.executable`` is empty.
|
||||||
|
- ``/dev/null`` / ``os.devnull`` may not be available.
|
||||||
|
|
||||||
|
|
||||||
# Detect WebAssembly builds
|
# Detect WebAssembly builds
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue