"BrokenIter",
"in_systemd_nspawn_sync_suppressed",
"run_no_yield_async_fn", "run_yielding_async_fn", "async_yield",
- "reset_code", "on_github_actions"
+ "reset_code", "on_github_actions",
+ "requires_root_user", "requires_non_root_user",
]
C0 control characters defined as the byte range 0x00-0x1F, and 0x7F.
"""
return [chr(c) for c in range(0x00, 0x20)] + ["\x7F"]
+
+
+_ROOT_IN_POSIX = hasattr(os, 'geteuid') and os.geteuid() == 0
+requires_root_user = unittest.skipUnless(_ROOT_IN_POSIX, "test needs root privilege")
+requires_non_root_user = unittest.skipIf(_ROOT_IN_POSIX, "test needs non-root account")
from test.support import import_helper, warnings_helper
from test.support import os_helper
from test.support import refleak_helper
+from test.support import requires_root_user
from test.support import socket_helper
import unittest
import textwrap
self.assertEqual(os.stat(self._path).st_mode, mode)
+ @requires_root_user
@unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
def test_ownership_after_flush(self):
# See issue gh-117467
else:
self.skipTest("test needs more than one group")
- try:
- os.chown(self._path, other_uid, other_gid)
- except OSError:
- self.skipTest('test needs root privilege')
+ os.chown(self._path, other_uid, other_gid)
# Change permissions as in test_permissions_after_flush.
mode = st.st_mode | 0o666
os.chmod(self._path, mode)
from test.support import os_helper
from test.support import socket_helper
from test.support import infinite_recursion
+from test.support import requires_root_user
+from test.support import requires_non_root_user
from test.support import warnings_helper
from platform import win32_is_iot
from .utils import create_file
from test.support.os_helper import FakePath
-root_in_posix = False
-if hasattr(os, 'geteuid'):
- root_in_posix = (os.geteuid() == 0)
-
# Detect whether we're on a Linux system that uses the (now outdated
# and unmaintained) linuxthreads threading library. There's an issue
# when combining linuxthreads with a failed execv call: see
gid = os.stat(os_helper.TESTFN).st_gid
self.assertEqual(gid, gid_2)
- @unittest.skipUnless(root_in_posix and len(all_users) > 1,
- "test needs root privilege and more than one user")
+ @requires_root_user
+ @unittest.skipUnless(len(all_users) > 1, "test needs more than one user")
def test_chown_with_root(self):
uid_1, uid_2 = all_users[:2]
gid = os.stat(os_helper.TESTFN).st_gid
uid = os.stat(os_helper.TESTFN).st_uid
self.assertEqual(uid, uid_2)
- @unittest.skipUnless(not root_in_posix and len(all_users) > 1,
- "test needs non-root account and more than one user")
+ @requires_non_root_user
+ @unittest.skipUnless(len(all_users) > 1, "test needs and more than one user")
def test_chown_without_permission(self):
uid_1, uid_2 = all_users[:2]
gid = os.stat(os_helper.TESTFN).st_gid
from test.support import is_emscripten, is_wasi, is_wasm32
from test.support import infinite_recursion
from test.support import os_helper
+from test.support import requires_root_user
from test.support.os_helper import TESTFN, FS_NONASCII, FakePath
try:
import fcntl
posix = None
-root_in_posix = False
-if hasattr(os, 'geteuid'):
- root_in_posix = (os.geteuid() == 0)
-
-
def patch_replace(old_test):
def new_replace(self, target):
raise OSError(errno.EXDEV, "Cross-device link", self, target)
self.assertRaises(FileNotFoundError, source.copy, target)
@unittest.skipIf(sys.platform == "win32" or sys.platform == "wasi", "directories are always readable on Windows and WASI")
- @unittest.skipIf(root_in_posix, "test fails with root privilege")
+ @requires_root_user
def test_copy_dir_no_read_permission(self):
base = self.cls(self.base)
source = base / 'dirE'
self.assertEqual(expected_name, p.owner())
@unittest.skipUnless(pwd, "the pwd module is needed for this test")
- @unittest.skipUnless(root_in_posix, "test needs root privilege")
+ @requires_root_user
def test_owner_no_follow_symlinks(self):
all_users = [u.pw_uid for u in pwd.getpwall()]
if len(all_users) < 2:
self.assertEqual(expected_name, p.group())
@unittest.skipUnless(grp, "the grp module is needed for this test")
- @unittest.skipUnless(root_in_posix, "test needs root privilege")
+ @requires_root_user
def test_group_no_follow_symlinks(self):
all_groups = [g.gr_gid for g in grp.getgrall()]
if len(all_groups) < 2: