| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9b08f8c commit 86b8617
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -71,7 +71,8 @@ | |||
| 71 | 71 | "BrokenIter", | |
| 72 | 72 | "in_systemd_nspawn_sync_suppressed", | |
| 73 | 73 | "run_no_yield_async_fn", "run_yielding_async_fn", "async_yield", | |
| 74 | - "reset_code", "on_github_actions" | ||
| 74 | + "reset_code", "on_github_actions", | ||
| 75 | + "requires_root_user", "requires_non_root_user", | ||
| 75 | 76 | ] | |
| 76 | 77 | ||
| 77 | 78 | ||
@@ -3317,3 +3318,8 @@ def control_characters_c0() -> list[str]: | |||
| 3317 | 3318 | C0 control characters defined as the byte range 0x00-0x1F, and 0x7F. | |
| 3318 | 3319 | """ | |
| 3319 | 3320 | return [chr(c) for c in range(0x00, 0x20)] + ["\x7F"] | |
| 3321 | + | ||
| 3322 | + | ||
| 3323 | + _ROOT_IN_POSIX = hasattr(os, 'geteuid') and os.geteuid() == 0 | ||
| 3324 | + requires_root_user = unittest.skipUnless(_ROOT_IN_POSIX, "test needs root privilege") | ||
| 3325 | + requires_non_root_user = unittest.skipIf(_ROOT_IN_POSIX, "test needs non-root account") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | from test.support import import_helper, warnings_helper | |
| 12 | 12 | from test.support import os_helper | |
| 13 | 13 | from test.support import refleak_helper | |
| 14 | + from test.support import requires_root_user | ||
| 14 | 15 | from test.support import socket_helper | |
| 15 | 16 | import unittest | |
| 16 | 17 | import textwrap | |
@@ -1086,6 +1087,7 @@ def test_permissions_after_flush(self): | |||
| 1086 | 1087 | ||
| 1087 | 1088 | self.assertEqual(os.stat(self._path).st_mode, mode) | |
| 1088 | 1089 | ||
| 1090 | + @requires_root_user | ||
| 1089 | 1091 | @unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown') | |
| 1090 | 1092 | def test_ownership_after_flush(self): | |
| 1091 | 1093 | # See issue gh-117467 | |
@@ -1108,10 +1110,7 @@ def test_ownership_after_flush(self): | |||
| 1108 | 1110 | else: | |
| 1109 | 1111 | self.skipTest("test needs more than one group") | |
| 1110 | 1112 | ||
| 1111 | - try: | ||
| 1112 | - os.chown(self._path, other_uid, other_gid) | ||
| 1113 | - except OSError: | ||
| 1114 | - self.skipTest('test needs root privilege') | ||
| 1113 | + os.chown(self._path, other_uid, other_gid) | ||
| 1115 | 1114 | # Change permissions as in test_permissions_after_flush. | |
| 1116 | 1115 | mode = st.st_mode | 0o666 | |
| 1117 | 1116 | os.chmod(self._path, mode) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,8 @@ | |||
| 33 | 33 | from test.support import os_helper | |
| 34 | 34 | from test.support import socket_helper | |
| 35 | 35 | from test.support import infinite_recursion | |
| 36 | + from test.support import requires_root_user | ||
| 37 | + from test.support import requires_non_root_user | ||
| 36 | 38 | from test.support import warnings_helper | |
| 37 | 39 | from platform import win32_is_iot | |
| 38 | 40 | from .utils import create_file | |
@@ -67,10 +69,6 @@ | |||
| 67 | 69 | from test.support.os_helper import FakePath | |
| 68 | 70 | ||
| 69 | 71 | ||
| 70 | - root_in_posix = False | ||
| 71 | - if hasattr(os, 'geteuid'): | ||
| 72 | - root_in_posix = (os.geteuid() == 0) | ||
| 73 | - | ||
| 74 | 72 | # Detect whether we're on a Linux system that uses the (now outdated | |
| 75 | 73 | # and unmaintained) linuxthreads threading library. There's an issue | |
| 76 | 74 | # when combining linuxthreads with a failed execv call: see | |
@@ -2257,8 +2255,8 @@ def test_chown_gid(self): | |||
| 2257 | 2255 | gid = os.stat(os_helper.TESTFN).st_gid | |
| 2258 | 2256 | self.assertEqual(gid, gid_2) | |
| 2259 | 2257 | ||
| 2260 | - @unittest.skipUnless(root_in_posix and len(all_users) > 1, | ||
| 2261 | - "test needs root privilege and more than one user") | ||
| 2258 | + @requires_root_user | ||
| 2259 | + @unittest.skipUnless(len(all_users) > 1, "test needs more than one user") | ||
| 2262 | 2260 | def test_chown_with_root(self): | |
| 2263 | 2261 | uid_1, uid_2 = all_users[:2] | |
| 2264 | 2262 | gid = os.stat(os_helper.TESTFN).st_gid | |
@@ -2269,8 +2267,8 @@ def test_chown_with_root(self): | |||
| 2269 | 2267 | uid = os.stat(os_helper.TESTFN).st_uid | |
| 2270 | 2268 | self.assertEqual(uid, uid_2) | |
| 2271 | 2269 | ||
| 2272 | - @unittest.skipUnless(not root_in_posix and len(all_users) > 1, | ||
| 2273 | - "test needs non-root account and more than one user") | ||
| 2270 | + @requires_non_root_user | ||
| 2271 | + @unittest.skipUnless(len(all_users) > 1, "test needs and more than one user") | ||
| 2274 | 2272 | def test_chown_without_permission(self): | |
| 2275 | 2273 | uid_1, uid_2 = all_users[:2] | |
| 2276 | 2274 | gid = os.stat(os_helper.TESTFN).st_gid | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | from test.support import is_emscripten, is_wasi, is_wasm32 | |
| 21 | 21 | from test.support import infinite_recursion | |
| 22 | 22 | from test.support import os_helper | |
| 23 | + from test.support import requires_root_user | ||
| 23 | 24 | from test.support.os_helper import TESTFN, FS_NONASCII, FakePath | |
| 24 | 25 | try: | |
| 25 | 26 | import fcntl | |
@@ -35,11 +36,6 @@ | |||
| 35 | 36 | posix = None | |
| 36 | 37 | ||
| 37 | 38 | ||
| 38 | - root_in_posix = False | ||
| 39 | - if hasattr(os, 'geteuid'): | ||
| 40 | - root_in_posix = (os.geteuid() == 0) | ||
| 41 | - | ||
| 42 | - | ||
| 43 | 39 | def patch_replace(old_test): | |
| 44 | 40 | def new_replace(self, target): | |
| 45 | 41 | raise OSError(errno.EXDEV, "Cross-device link", self, target) | |
@@ -1554,7 +1550,7 @@ def raiser(*args, **kwargs): | |||
| 1554 | 1550 | self.assertRaises(FileNotFoundError, source.copy, target) | |
| 1555 | 1551 | ||
| 1556 | 1552 | @unittest.skipIf(sys.platform == "win32" or sys.platform == "wasi", "directories are always readable on Windows and WASI") | |
| 1557 | - @unittest.skipIf(root_in_posix, "test fails with root privilege") | ||
| 1553 | + @requires_root_user | ||
| 1558 | 1554 | def test_copy_dir_no_read_permission(self): | |
| 1559 | 1555 | base = self.cls(self.base) | |
| 1560 | 1556 | source = base / 'dirE' | |
@@ -2027,7 +2023,7 @@ def test_owner(self): | |||
| 2027 | 2023 | self.assertEqual(expected_name, p.owner()) | |
| 2028 | 2024 | ||
| 2029 | 2025 | @unittest.skipUnless(pwd, "the pwd module is needed for this test") | |
| 2030 | - @unittest.skipUnless(root_in_posix, "test needs root privilege") | ||
| 2026 | + @requires_root_user | ||
| 2031 | 2027 | def test_owner_no_follow_symlinks(self): | |
| 2032 | 2028 | all_users = [u.pw_uid for u in pwd.getpwall()] | |
| 2033 | 2029 | if len(all_users) < 2: | |
@@ -2062,7 +2058,7 @@ def test_group(self): | |||
| 2062 | 2058 | self.assertEqual(expected_name, p.group()) | |
| 2063 | 2059 | ||
| 2064 | 2060 | @unittest.skipUnless(grp, "the grp module is needed for this test") | |
| 2065 | - @unittest.skipUnless(root_in_posix, "test needs root privilege") | ||
| 2061 | + @requires_root_user | ||
| 2066 | 2062 | def test_group_no_follow_symlinks(self): | |
| 2067 | 2063 | all_groups = [g.gr_gid for g in grp.getgrall()] | |
| 2068 | 2064 | if len(all_groups) < 2: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments