8000 gh-90473: Misc test fixes for WASI (GH-93218) · python/cpython@0fb70ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fb70ce

Browse files
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 1f134e9) Co-authored-by: Christian Heimes <christian@python.org>
1 parent 307dacd commit 0fb70ce

File tree

8 files changed

+26
-7
lines changed

8 files changed

+26
-7
lines changed

Lib/distutils/tests/test_build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class BuildTestCase(support.TempdirManager,
1212
support.LoggingSilencer,
1313
unittest.TestCase):
1414

15+
@unittest.skipUnless(sys.executable, "test requires sys.executable")
1516
def test_finalize_options(self):
1617
pkg_dir, dist = self.create_dist()
1718
cmd = build(dist)

Lib/lib2to3/tests/test_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_load_grammar_from_pickle(self):
6363

6464
@unittest.skipIf(sys.executable is None, 'sys.executable required')
6565
@unittest.skipIf(
66-
sys.platform == 'emscripten', 'requires working subprocess'
66+
sys.platform in {'emscripten', 'wasi'}, 'requires working subprocess'
6767
)
6868
def test_load_grammar_from_subprocess(self):
6969
tmpdir = tempfile.mkdtemp()

Lib/test/test_netrc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import netrc, os, unittest, sys, textwrap
22
from test.support import os_helper, run_unittest
33

4+
try:
5+
import pwd
6+
except ImportError:
7+
pwd = None
8+
49
temp_filename = os_helper.TESTFN
510

611
class NetrcTestCase(unittest.TestCase):
@@ -266,6 +271,7 @@ def test_comment_at_end_of_machine_line_pass_has_hash(self):
266271

267272

268273
@unittest.skipUnless(os.name == 'posix', 'POSIX only test')
274+
@unittest.skipIf(pwd is None, 'security check requires pwd module')
269275
def test_security(self):
270276
# This test is incomplete since we are normally not run as root and
271277
# therefore can't test the file ownership being wrong.

Lib/test/test_os.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,6 +1765,7 @@ def test_remove_nothing(self):
17651765
self.assertTrue(os.path.exists(os_helper.TESTFN))
17661766

17671767

1768+
@unittest.skipIf(support.is_wasi, "WASI has no /dev/null")
17681769
class DevNullTests(unittest.TestCase):
17691770
def test_devnull(self):
17701771
with open(os.devnull, 'wb', 0) as f:
@@ -2111,6 +2112,7 @@ def test_chmod(self):
21112112
self.assertRaises(OSError, os.chmod, os_helper.TESTFN, 0)
21122113

21132114

2115+
@unittest.skipIf(support.is_wasi, "Cannot create invalid FD on WASI.")
21142116
class TestInvalidFD(unittest.TestCase):
21152117
singles = ["fchdir", "dup", "fdatasync", "fstat",
21162118
"fstatvfs", "fsync", "tcgetpgrp", "ttyname"]

Lib/test/test_pathlib.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from unittest import mock
1414

1515
from test.support import import_helper
16-
from test.support import is_emscripten
16+
from test.support import is_emscripten, is_wasi
1717
from test.support import os_helper
1818
from test.support.os_helper import TESTFN, FakePath
1919

@@ -1530,6 +1530,7 @@ def test_empty_path(self):
15301530
p = self.cls('')
15311531
self.assertEqual(p.stat(), os.stat('.'))
15321532

1533+
@unittest.skipIf(is_wasi, "WASI has no user accounts.")
15331534
def test_expanduser_common(self):
15341535
P = self.cls
15351536
p = P('~')
@@ -2530,7 +2531,8 @@ def _check_symlink_loop(self, *args, strict=True):
25302531
print(path.resolve(strict))
25312532

25322533
@unittest.skipIf(
2533-
is_emscripten, "umask is not implemented on Emscripten."
2534+
is_emscripten or is_wasi,
2535+
"umask is not implemented on Emscripten/WASI."
25342536
)
25352537
def test_open_mode(self):
25362538
old_mask = os.umask(0)
@@ -2556,7 +2558,8 @@ def test_resolve_root(self):
25562558
os.chdir(current_directory)
25572559

25582560
@unittest.skipIf(
2559-
is_emscripten, "umask is not implemented on Emscripten."
2561+
is_emscripten or is_wasi,
2562+
"umask is not implemented on Emscripten/WASI."
25602563
)
25612564
def test_touch_mode(self):
25622565
old_mask = os.umask(0)

Lib/test/test_tarfile.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,10 @@ def test_stream_padding(self):
14981498

14991499
@unittest.skipUnless(sys.platform != "win32" and hasattr(os, "umask"),
15001500
"Missing umask implementation")
1501-
@unittest.skipIf(support.is_emscripten, "Emscripten's umask is a stub.")
1501+
@unittest.skipIf(
1502+
support.is_emscripten or support.is_wasi,
1503+
"Emscripten's/WASI's umask is a stub."
1504+
)
15021505
def test_file_mode(self):
15031506
# Test for issue #8464: Create files with correct
15041507
# permissions.

Lib/test/test_unicode_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _test_single(self, filename):
110110
os.unlink(filename)
111111
self.assertTrue(not os.path.exists(filename))
112112
# and again with os.open.
113-
f = os.open(filename, os.O_CREAT)
113+
f = os.open(filename, os.O_CREAT | os.O_WRONLY)
114114
os.close(f)
115115
try:
116116
self._do_single(filename)

Tools/wasm/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,11 @@ are:
239239
yet. A future version of WASI may provide a limited ``set_permissions`` API.
240240
- File locking (``fcntl``) is not available.
241241
- ``os.pipe()``, ``os.mkfifo()``, and ``os.mknod()`` are not supported.
242-
- ``process_time`` clock does not work.
242+
- ``process_time`` does not work as expected because it's implemented using
243+
wall clock.
244+
- ``os.umask`` is a stub.
245+
- ``sys.executable`` is empty.
246+
- ``/dev/null`` / ``os.devnull`` may not be available.
243247

244248

245249
# Detect WebAssembly builds

0 commit comments

Comments
 (0)
0