|
41 | 41 | import _winapi |
42 | 42 | except ImportError: |
43 | 43 | _winapi = None |
44 | | -try: |
45 | | - import grp |
46 | | - groups = [g.gr_gid for g in grp.getgrall() if getpass.getuser() in g.gr_mem] |
47 | | - if hasattr(os, 'getgid'): |
48 | | - process_gid = os.getgid() |
49 | | - if process_gid not in groups: |
50 | | - groups.append(process_gid) |
51 | | -except ImportError: |
52 | | - groups = [] |
53 | 44 | try: |
54 | 45 | import pwd |
55 | 46 | all_users = [u.pw_uid for u in pwd.getpwall()] |
@@ -1238,13 +1229,19 @@ def test_chown_uid_gid_arguments_must_be_index(self): |
1238 | 1229 | self.assertIsNone(os.chown(support.TESTFN, uid, gid)) |
1239 | 1230 | self.assertIsNone(os.chown(support.TESTFN, -1, -1)) |
1240 | 1231 |
|
1241 | | - @unittest.skipUnless(len(groups) > 1, "test needs more than one group") |
1242 | | - def test_chown(self): |
| 1232 | + @unittest.skipUnless(hasattr(os, 'getgroups'), 'need os.getgroups') |
| 1233 | + def test_chown_gid(self): |
| 1234 | + groups = os.getgroups() |
| 1235 | + if len(groups) < 2: |
| 1236 | + self.skipTest("test needs at least 2 groups") |
| 1237 | + |
1243 | 1238 | gid_1, gid_2 = groups[:2] |
1244 | 1239 | uid = os.stat(support.TESTFN).st_uid |
| 1240 | + |
1245 | 1241 | os.chown(support.TESTFN, uid, gid_1) |
1246 | 1242 | gid = os.stat(support.TESTFN).st_gid |
1247 | 1243 | self.assertEqual(gid, gid_1) |
| 1244 | + |
1248 | 1245 | os.chown(support.TESTFN, uid, gid_2) |
1249 | 1246 | gid = os.stat(support.TESTFN).st_gid |
1250 | 1247 | self.assertEqual(gid, gid_2) |
|
0 commit comments