Issue #7333: The `posix` module gains an `initgroups()` function providing
access to the initgroups(3) C library call on Unix systems which implement
it.  Patch by Jean-Paul Calderone.
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py
index aaa3841..c6da157 100644
--- a/Lib/test/test_posix.py
+++ b/Lib/test/test_posix.py
@@ -5,6 +5,7 @@
 # Skip these tests if there is no posix module.
 posix = test_support.import_module('posix')
 
+import errno
 import time
 import os
 import pwd
@@ -83,6 +84,27 @@
                 new_group_ids = (current_group_ids[0]+1, -1, -1)
                 self.assertRaises(OSError, posix.setresgid, *new_group_ids)
 
+    @unittest.skipUnless(hasattr(posix, 'initgroups'),
+                         "test needs os.initgroups()")
+    def test_initgroups(self):
+        # It takes a string and an integer; check that it raises a TypeError
+        # for other argument lists.
+        self.assertRaises(TypeError, posix.initgroups)
+        self.assertRaises(TypeError, posix.initgroups, None)
+        self.assertRaises(TypeError, posix.initgroups, 3, "foo")
+        self.assertRaises(TypeError, posix.initgroups, "foo", 3, object())
+
+        # If a non-privileged user invokes it, it should fail with OSError
+        # EPERM.
+        if os.getuid() != 0:
+            name = pwd.getpwuid(posix.getuid()).pw_name
+            try:
+                posix.initgroups(name, 13)
+            except OSError as e:
+                self.assertEquals(e.errno, errno.EPERM)
+            else:
+                self.fail("Expected OSError to be raised by initgroups")
+
     def test_statvfs(self):
         if hasattr(posix, 'statvfs'):
             self.assertTrue(posix.statvfs(os.curdir))