Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
Next Next commit
Move all_users and all_groups into tests
  • Loading branch information
kamilturek committed Dec 2, 2023
commit 9077bc302164217a756afabd4d25c61d6fabd296
24 changes: 8 additions & 16 deletions Lib/test/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@ def test_is_notimplemented(self):
self.assertTrue(isinstance(pathlib.UnsupportedOperation(), NotImplementedError))


try:
import pwd
all_users = [u.pw_uid for u in pwd.getpwall()]
except (ImportError, AttributeError):
all_users = []


try:
import grp
all_groups = [g.gr_gid for g in grp.getgrall()]
except (ImportError, AttributeError):
all_groups = []


# Make sure any symbolic links in the base test path are resolved.
BASE = os.path.realpath(TESTFN)
join = lambda *x: os.path.join(BASE, *x)
Expand Down Expand Up @@ -2601,8 +2587,11 @@ def test_owner(self):

@unittest.skipUnless(pwd, "the pwd module is needed for this test")
@unittest.skipUnless(root_in_posix, "test needs root privilege")
@unittest.skipUnless(len(all_users) > 1, "test needs more than one user")
def test_owner_no_follow_symlinks(self):
all_users = [u.pw_uid for u in pwd.getpwall()]
if len(all_users) < 2:
self.skipTest("test needs more than one user")

target = self.cls(BASE) / 'fileA'
link = self.cls(BASE) / 'linkA'

Expand Down Expand Up @@ -2633,8 +2622,11 @@ def test_group(self):

@unittest.skipUnless(grp, "the grp module is needed for this test")
@unittest.skipUnless(root_in_posix, "test needs root privilege")
@unittest.skipUnless(len(all_groups) > 1, "test needs more than one group")
def test_group_no_follow_symlinks(self):
all_groups = [g.gr_gid for g in grp.getgrall()]
if len(all_groups) < 2:
self.skipTest("test needs more than one group")

target = self.cls(BASE) / 'fileA'
link = self.cls(BASE) / 'linkA'

Expand Down