Update test_posix from v3.14.2

This commit is contained in:
CPython Developers authored and Jeong, YunWon committed 2026-02-03 22:10:31 +09:00
1 parent f939a06aa9
commit ac1dcf7d4b
1 file changed
+68 -14
+68 -14
View File
@@ -583,7 +583,7 @@ class PosixTester(unittest.TestCase):
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):
@@ -1018,7 +1018,7 @@ class PosixTester(unittest.TestCase):
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:
@@ -1075,7 +1075,7 @@ class PosixTester(unittest.TestCase):
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()
@@ -1110,7 +1110,7 @@ class PosixTester(unittest.TestCase):
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
@@ -1146,7 +1146,7 @@ class PosixTester(unittest.TestCase):
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)
@@ -1370,6 +1370,14 @@ class PosixTester(unittest.TestCase):
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:
@@ -1525,6 +1533,51 @@ class PosixTester(unittest.TestCase):
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):
@@ -1570,7 +1623,7 @@ class TestPosixDirFd(unittest.TestCase):
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):
@@ -1973,7 +2026,7 @@ class _PosixSpawnMixin:
[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")
@@ -1994,14 +2047,15 @@ class _PosixSpawnMixin:
)
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)
@@ -2081,7 +2135,7 @@ class _PosixSpawnMixin:
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)
@@ -2186,12 +2240,12 @@ class TestPosixWeaklinking(unittest.TestCase):
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")