Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update test_posix from v3.14.2
  • Loading branch information
CPython Developers authored and youknowone committed Feb 3, 2026
commit ac1dcf7d4bfc216efc595aa9f4c83f9c20baecba
82 changes: 68 additions & 14 deletions Lib/test/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_confstr(self):
self.assertGreater(len(path), 0)
self.assertEqual(posix.confstr(posix.confstr_names["CS_PATH"]), path)

@unittest.expectedFailureIf(sys.platform in ('darwin', 'linux'), '''TODO: RUSTPYTHON; AssertionError: "configuration names must be strings or integers" does not match "Expected type 'str' but 'float' found."''')
@unittest.expectedFailureIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; AssertionError: \"configuration names must be strings or integers\" does not match \"Expected type 'str' but 'float' found.\"")
@unittest.skipUnless(hasattr(posix, 'sysconf'),
'test needs posix.sysconf()')
def test_sysconf(self):
Expand Down Expand Up @@ -1018,7 +1018,7 @@ def test_chmod_dir(self):
target = self.tempdir()
self.check_chmod(posix.chmod, target)

@unittest.skipIf(sys.platform in ('darwin', 'linux'), 'TODO: RUSTPYTHON; crash')
@unittest.skipIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; crash")
@os_helper.skip_unless_working_chmod
def test_fchmod_file(self):
with open(os_helper.TESTFN, 'wb+') as f:
Expand Down Expand Up @@ -1075,7 +1075,7 @@ def test_chmod_file_symlink(self):
self.check_chmod_link(posix.chmod, target, link)
self.check_chmod_link(posix.chmod, target, link, follow_symlinks=True)

@unittest.skipIf(sys.platform == 'win32', 'TODO: RUSTPYTHON; flaky')
@unittest.skipIf(sys.platform == "win32", "TODO: RUSTPYTHON; flaky")
@os_helper.skip_unless_symlink
def test_chmod_dir_symlink(self):
target = self.tempdir()
Expand Down Expand Up @@ -1110,7 +1110,7 @@ def test_lchmod_dir_symlink(self):

def _test_chflags_regular_file(self, chflags_func, target_file, **kwargs):
st = os.stat(target_file)
self.assertTrue(hasattr(st, 'st_flags'))
self.assertHasAttr(st, 'st_flags')

# ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
flags = st.st_flags | stat.UF_IMMUTABLE
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def test_lchflags_regular_file(self):
def test_lchflags_symlink(self):
testfn_st = os.stat(os_helper.TESTFN)

self.assertTrue(hasattr(testfn_st, 'st_flags'))
self.assertHasAttr(testfn_st, 'st_flags')

self.addCleanup(os_helper.unlink, _DUMMY_SYMLINK)
os.symlink(os_helper.TESTFN, _DUMMY_SYMLINK)
Expand Down Expand Up @@ -1370,6 +1370,14 @@ def test_sched_param(self):
self.assertNotEqual(newparam, param)
self.assertEqual(newparam.sched_priority, 0)

@requires_sched
def test_bug_140634(self):
sched_priority = float('inf') # any new reference
param = posix.sched_param(sched_priority)
param.__reduce__()
del sched_priority, param # should not crash
support.gc_collect() # just to be sure

@unittest.skipUnless(hasattr(posix, "sched_rr_get_interval"), "no function")
def test_sched_rr_get_interval(self):
try:
Expand Down Expand Up @@ -1525,6 +1533,51 @@ def test_pidfd_open(self):
self.assertEqual(cm.exception.errno, errno.EINVAL)
os.close(os.pidfd_open(os.getpid(), 0))

@os_helper.skip_unless_hardlink
@os_helper.skip_unless_symlink
def test_link_follow_symlinks(self):
default_follow = sys.platform.startswith(
('darwin', 'freebsd', 'netbsd', 'openbsd', 'dragonfly', 'sunos5'))
default_no_follow = sys.platform.startswith(('win32', 'linux'))
orig = os_helper.TESTFN
symlink = orig + 'symlink'
posix.symlink(orig, symlink)
self.addCleanup(os_helper.unlink, symlink)

with self.subTest('no follow_symlinks'):
# no follow_symlinks -> platform depending
link = orig + 'link'
posix.link(symlink, link)
self.addCleanup(os_helper.unlink, link)
if os.link in os.supports_follow_symlinks or default_follow:
self.assertEqual(posix.lstat(link), posix.lstat(orig))
elif default_no_follow:
self.assertEqual(posix.lstat(link), posix.lstat(symlink))

with self.subTest('follow_symlinks=False'):
# follow_symlinks=False -> duplicate the symlink itself
link = orig + 'link_nofollow'
try:
posix.link(symlink, link, follow_symlinks=False)
except NotImplementedError:
if os.link in os.supports_follow_symlinks or default_no_follow:
raise
else:
self.addCleanup(os_helper.unlink, link)
self.assertEqual(posix.lstat(link), posix.lstat(symlink))

with self.subTest('follow_symlinks=True'):
# follow_symlinks=True -> duplicate the target file
link = orig + 'link_following'
try:
posix.link(symlink, link, follow_symlinks=True)
except NotImplementedError:
if os.link in os.supports_follow_symlinks or default_follow:
raise
else:
self.addCleanup(os_helper.unlink, link)
self.assertEqual(posix.lstat(link), posix.lstat(orig))


# tests for the posix *at functions follow
class TestPosixDirFd(unittest.TestCase):
Expand Down Expand Up @@ -1570,7 +1623,7 @@ def test_chown_dir_fd(self):
with self.prepare_file() as (dir_fd, name, fullname):
posix.chown(name, os.getuid(), os.getgid(), dir_fd=dir_fd)

@unittest.expectedFailureIf(sys.platform in ('darwin', 'linux'), 'TODO: RUSTPYTHON; AssertionError: RuntimeWarning not triggered')
@unittest.expectedFailureIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; AssertionError: RuntimeWarning not triggered")
@unittest.skipUnless(os.stat in os.supports_dir_fd, "test needs dir_fd support in os.stat()")
def test_stat_dir_fd(self):
with self.prepare() as (dir_fd, name, fullname):
Expand Down Expand Up @@ -1973,7 +2026,7 @@ def test_setsigdef_wrong_type(self):
[sys.executable, "-c", "pass"],
os.environ, setsigdef=[signal.NSIG, signal.NSIG+1])

@unittest.expectedFailureIf(sys.platform in ('darwin', 'linux'), 'TODO: RUSTPYTHON; NotImplementedError: scheduler parameter is not yet implemented')
@unittest.expectedFailureIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; NotImplementedError: scheduler parameter is not yet implemented")
@requires_sched
@unittest.skipIf(sys.platform.startswith(('freebsd', 'netbsd')),
"bpo-34685: test can fail on BSD")
Expand All @@ -1994,14 +2047,15 @@ def test_setscheduler_only_param(self):
)
support.wait_process(pid, exitcode=0)

@unittest.expectedFailureIf(sys.platform in ('darwin', 'linux'), 'TODO: RUSTPYTHON; NotImplementedError: scheduler parameter is not yet implemented')
@unittest.expectedFailureIf(sys.platform in ("darwin", "linux"), "TODO: RUSTPYTHON; NotImplementedError: scheduler parameter is not yet implemented")
@requires_sched
@unittest.skipIf(sys.platform.startswith(('freebsd', 'netbsd')),
"bpo-34685: test can fail on BSD")
@unittest.skipIf(platform.libc_ver()[0] == 'glibc' and
os.sched_getscheduler(0) in [
os.SCHED_BATCH,
os.SCHED_IDLE],
os.SCHED_IDLE,
os.SCHED_DEADLINE],
"Skip test due to glibc posix_spawn policy")
def test_setscheduler_with_policy(self):
policy = os.sched_getscheduler(0)
Expand Down Expand Up @@ -2081,7 +2135,7 @@ def test_open_file(self):
with open(outfile, encoding="utf-8") as f:
self.assertEqual(f.read(), 'hello')

@unittest.expectedFailure # TODO: RUSTPYTHON; the rust runtime reopens closed stdio fds at startup, so this test fails, even though POSIX_SPAWN_CLOSE does actually have an effect
@unittest.expectedFailure # TODO: RUSTPYTHON; the rust runtime reopens closed stdio fds at startup, so this test fails, even though POSIX_SPAWN_CLOSE does actually have an effect
def test_close_file(self):
closefile = os_helper.TESTFN
self.addCleanup(os_helper.unlink, closefile)
Expand Down Expand Up @@ -2186,12 +2240,12 @@ def _verify_available(self, name):
def test_pwritev(self):
self._verify_available("HAVE_PWRITEV")
if self.mac_ver >= (10, 16):
self.assertTrue(hasattr(os, "pwritev"), "os.pwritev is not available")
self.assertTrue(hasattr(os, "preadv"), "os.readv is not available")
self.assertHasAttr(os, "pwritev")
self.assertHasAttr(os, "preadv")

else:
self.assertFalse(hasattr(os, "pwritev"), "os.pwritev is available")
self.assertFalse(hasattr(os, "preadv"), "os.readv is available")
self.assertNotHasAttr(os, "pwritev")
self.assertNotHasAttr(os, "preadv")

def test_stat(self):
self._verify_available("HAVE_FSTATAT")
Expand Down