Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,6 @@ def walk(self, top, **kwargs):
bdirs[:] = list(map(os.fsencode, dirs))
bfiles[:] = list(map(os.fsencode, files))


@unittest.skipUnless(hasattr(os, 'fwalk'), "Test needs os.fwalk()")
class BytesFwalkTests(FwalkTests):
"""Tests for os.walk() with bytes."""
Expand Down Expand Up @@ -2418,6 +2417,46 @@ def test_execve_invalid_env(self):
with self.assertRaises(ValueError):
os.execve(args[0], args, newenv)

# See https://github.com/python/cpython/issues/137934 and the other
# related issues for the reason why we cannot test this on Windows.
@unittest.expectedFailure # TODO: RUSTPYTHON; IndentationError: unexpected indentation
@unittest.skipIf(os.name == "nt", "POSIX-specific test")
@unittest.skipUnless(unix_shell and os.path.exists(unix_shell),
"requires a shell")
def test_execve_env_concurrent_mutation_with_fspath_posix(self):
# Prevent crash when mutating environment during parsing.
# Regression test for https://github.com/python/cpython/issues/143309.

message = "hello from execve"
code = """
import os, sys

class MyPath:
def __fspath__(self):
mutated.clear()
return b"pwn"

mutated = KEYS = VALUES = [MyPath()]

class MyEnv:
def __getitem__(self): raise RuntimeError("must not be called")
def __len__(self): return 1
def keys(self): return KEYS
def values(self): return VALUES

args = [{unix_shell!r}, '-c', 'echo \"{message!s}\"']
os.execve(args[0], args, MyEnv())
""".format(unix_shell=unix_shell, message=message)

# Make sure to forward "LD_*" variables so that assert_python_ok()
# can run correctly.
minimal = {k: v for k, v in os.environ.items() if k.startswith("LD_")}
with os_helper.EnvironmentVarGuard() as env:
env.clear()
env.update(minimal)
_, out, _ = assert_python_ok('-c', code, **env)
self.assertIn(bytes(message, "ascii"), out)

@unittest.skipUnless(sys.platform == "win32", "Win32-specific test")
def test_execve_with_empty_path(self):
# bpo-32890: Check GetLastError() misuse
Expand Down Expand Up @@ -2569,6 +2608,16 @@ def test_fpathconf_bad_fd(self):
self.check(os.pathconf, "PC_NAME_MAX")
self.check(os.fpathconf, "PC_NAME_MAX")

@unittest.skipUnless(hasattr(os, 'pathconf'), 'test needs os.pathconf()')
@unittest.skipIf(
support.linked_to_musl(),
'musl fpathconf ignores the file descriptor and returns a constant',
)
def test_pathconf_negative_fd_uses_fd_semantics(self):
with self.assertRaises(OSError) as ctx:
os.pathconf(-1, 1)
self.assertEqual(ctx.exception.errno, errno.EBADF)

@unittest.skipUnless(hasattr(os, 'ftruncate'), 'test needs os.ftruncate()')
def test_ftruncate(self):
self.check(os.truncate, 0)
Expand Down Expand Up @@ -2616,9 +2665,6 @@ def test_blocking(self):
self.check(os.set_blocking, True)





@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
class LinkTests(unittest.TestCase):
def setUp(self):
Expand Down
Loading