Issue #9344: Add os.getgrouplist().

This commit is contained in:
Ross Lagerwall 2011-06-10 07:30:30 +02:00
parent 10c30d6764
commit b0ae53d8a0
6 changed files with 368 additions and 252 deletions

View file

@ -569,6 +569,21 @@ class PosixTester(unittest.TestCase):
os.chdir(curdir)
support.rmtree(base_path)
@unittest.skipUnless(hasattr(posix, 'getgrouplist'), "test needs posix.getgrouplist()")
@unittest.skipUnless(hasattr(pwd, 'getpwuid'), "test needs pwd.getpwuid()")
@unittest.skipUnless(hasattr(os, 'getuid'), "test needs os.getuid()")
def test_getgrouplist(self):
with os.popen('id -G') as idg:
groups = idg.read().strip()
if not groups:
raise unittest.SkipTest("need working 'id -G'")
self.assertEqual(
set([int(x) for x in groups.split()]),
set(posix.getgrouplist(pwd.getpwuid(os.getuid())[0],
pwd.getpwuid(os.getuid())[3])))
@unittest.skipUnless(hasattr(os, 'getegid'), "test needs os.getegid()")
def test_getgroups(self):
with os.popen('id -G') as idg: