|
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 |
23 | 24 | from test.support.os_helper import TESTFN, FS_NONASCII, FakePath |
24 | 25 | try: |
25 | 26 | import fcntl |
|
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 |
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 |
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 |
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: |
@@ -3216,15 +3212,14 @@ def test_touch_mode(self): |
3216 | 3212 | st = os.stat(self.parser.join(self.base, 'masked_new_file')) |
3217 | 3213 | self.assertEqual(stat.S_IMODE(st.st_mode), 0o750) |
3218 | 3214 |
|
| 3215 | + @unittest.skipUnless(pwd, "the pwd module is needed for this test") |
3219 | 3216 | @unittest.skipUnless(hasattr(pwd, 'getpwall'), |
3220 | 3217 | 'pwd module does not expose getpwall()') |
3221 | 3218 | @unittest.skipIf(sys.platform == "vxworks", |
3222 | 3219 | "no home directory on VxWorks") |
3223 | 3220 | @needs_posix |
3224 | 3221 | def test_expanduser_posix(self): |
3225 | 3222 | P = self.cls |
3226 | | - import_helper.import_module('pwd') |
3227 | | - import pwd |
3228 | 3223 | pwdent = pwd.getpwuid(os.getuid()) |
3229 | 3224 | username = pwdent.pw_name |
3230 | 3225 | userhome = pwdent.pw_dir.rstrip('/') or '/' |
|
0 commit comments