|
42 | 42 | import _winapi |
43 | 43 | except ImportError: |
44 | 44 | _winapi = None |
45 | | -try: |
46 | | - import grp |
47 | | - groups = [g.gr_gid for g in grp.getgrall() if getpass.getuser() in g.gr_mem] |
48 | | - if hasattr(os, 'getgid'): |
49 | | - process_gid = os.getgid() |
50 | | - if process_gid not in groups: |
51 | | - groups.append(process_gid) |
52 | | -except ImportError: |
53 | | - groups = [] |
54 | 45 | try: |
55 | 46 | import pwd |
56 | 47 | all_users = [u.pw_uid for u in pwd.getpwall()] |
@@ -1320,13 +1311,19 @@ def test_chown_uid_gid_arguments_must_be_index(self): |
1320 | 1311 | self.assertIsNone(os.chown(support.TESTFN, uid, gid)) |
1321 | 1312 | self.assertIsNone(os.chown(support.TESTFN, -1, -1)) |
1322 | 1313 |
|
1323 | | - @unittest.skipUnless(len(groups) > 1, "test needs more than one group") |
1324 | | - def test_chown(self): |
| 1314 | + @unittest.skipUnless(hasattr(os, 'getgroups'), 'need os.getgroups') |
| 1315 | + def test_chown_gid(self): |
| 1316 | + groups = os.getgroups() |
| 1317 | + if len(groups) < 2: |
| 1318 | + self.skipTest("test needs at least 2 groups") |
| 1319 | + |
1325 | 1320 | gid_1, gid_2 = groups[:2] |
1326 | 1321 | uid = os.stat(support.TESTFN).st_uid |
| 1322 | + |
1327 | 1323 | os.chown(support.TESTFN, uid, gid_1) |
1328 | 1324 | gid = os.stat(support.TESTFN).st_gid |
1329 | 1325 | self.assertEqual(gid, gid_1) |
| 1326 | + |
1330 | 1327 | os.chown(support.TESTFN, uid, gid_2) |
1331 | 1328 | gid = os.stat(support.TESTFN).st_gid |
1332 | 1329 | self.assertEqual(gid, gid_2) |
|
0 commit comments