summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-06-25 15:06:24 (GMT)
committerGitHub <noreply@github.com>2019-06-25 15:06:24 (GMT)
commitd7c87d982d4ec4ba201bcee14324ae5e0e90581f (patch)
tree5be3f4190e32dc2956e6f40ba8d9e64bff1b5e5a /Lib
parent3939c321c90283b49eddde762656e4b1940e7150 (diff)
downloadcpython-d7c87d982d4ec4ba201bcee14324ae5e0e90581f.zip
cpython-d7c87d982d4ec4ba201bcee14324ae5e0e90581f.tar.gz
cpython-d7c87d982d4ec4ba201bcee14324ae5e0e90581f.tar.bz2
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().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_os.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
index b540fcb..527f814 100644
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -43,15 +43,6 @@ try:
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()]
except (ImportError, AttributeError):
@@ -1320,13 +1311,19 @@ class ChownFileTests(unittest.TestCase):
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)