Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.7] bpo-37400: Fix test_os.test_chown() (GH-14374) #14378

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@
import _winapi
except ImportError:
_winapi = None
try:
import grp
groups = [g.gr_gid for g in grp.getgrall() if getpass.getuser() in g.gr_mem]
if hasattr(os, 'getgid'):
process_gid = os.getgid()
if process_gid not in groups:
groups.append(process_gid)
except ImportError:
groups = []
try:
import pwd
all_users = [u.pw_uid for u in pwd.getpwall()]
Expand Down Expand Up @@ -1238,13 +1229,19 @@ def test_chown_uid_gid_arguments_must_be_index(self):
self.assertIsNone(os.chown(support.TESTFN, uid, gid))
self.assertIsNone(os.chown(support.TESTFN, -1, -1))

@unittest.skipUnless(len(groups) > 1, "test needs more than one group")
def test_chown(self):
@unittest.skipUnless(hasattr(os, 'getgroups'), 'need os.getgroups')
def test_chown_gid(self):
groups = os.getgroups()
if len(groups) < 2:
self.skipTest("test needs at least 2 groups")

gid_1, gid_2 = groups[:2]
uid = os.stat(support.TESTFN).st_uid

os.chown(support.TESTFN, uid, gid_1)
gid = os.stat(support.TESTFN).st_gid
self.assertEqual(gid, gid_1)

os.chown(support.TESTFN, uid, gid_2)
gid = os.stat(support.TESTFN).st_gid
self.assertEqual(gid, gid_2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix test_os.test_chown(): use os.getgroups() rather than grp.getgrall()
to get groups. Rename also the test to test_chown_gid().