mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
bpo-37400: Fix test_os.test_chown() (GH-14374)
Use os.getgroups() rather than grp.getgrall() to get groups.
Rename also the test to test_chown_gid().
(cherry picked from commit d7c87d982d
)
Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
parent
25fbe33b92
commit
12d174bed9
2 changed files with 10 additions and 11 deletions
|
@ -42,15 +42,6 @@ try:
|
||||||
import _winapi
|
import _winapi
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_winapi = None
|
_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:
|
try:
|
||||||
import pwd
|
import pwd
|
||||||
all_users = [u.pw_uid for u in pwd.getpwall()]
|
all_users = [u.pw_uid for u in pwd.getpwall()]
|
||||||
|
@ -1320,13 +1311,19 @@ class ChownFileTests(unittest.TestCase):
|
||||||
self.assertIsNone(os.chown(support.TESTFN, uid, gid))
|
self.assertIsNone(os.chown(support.TESTFN, uid, gid))
|
||||||
self.assertIsNone(os.chown(support.TESTFN, -1, -1))
|
self.assertIsNone(os.chown(support.TESTFN, -1, -1))
|
||||||
|
|
||||||
@unittest.skipUnless(len(groups) > 1, "test needs more than one group")
|
@unittest.skipUnless(hasattr(os, 'getgroups'), 'need os.getgroups')
|
||||||
def test_chown(self):
|
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]
|
gid_1, gid_2 = groups[:2]
|
||||||
uid = os.stat(support.TESTFN).st_uid
|
uid = os.stat(support.TESTFN).st_uid
|
||||||
|
|
||||||
os.chown(support.TESTFN, uid, gid_1)
|
os.chown(support.TESTFN, uid, gid_1)
|
||||||
gid = os.stat(support.TESTFN).st_gid
|
gid = os.stat(support.TESTFN).st_gid
|
||||||
self.assertEqual(gid, gid_1)
|
self.assertEqual(gid, gid_1)
|
||||||
|
|
||||||
os.chown(support.TESTFN, uid, gid_2)
|
os.chown(support.TESTFN, uid, gid_2)
|
||||||
gid = os.stat(support.TESTFN).st_gid
|
gid = os.stat(support.TESTFN).st_gid
|
||||||
self.assertEqual(gid, gid_2)
|
self.assertEqual(gid, gid_2)
|
||||||
|
|
|
@ -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().
|
Loading…
Add table
Add a link
Reference in a new issue