diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-12-02 20:46:48 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-12-02 20:46:48 (GMT) |
commit | b7572f08f48c4b29c137c7b62f10be9436b6efa3 (patch) | |
tree | 326485f0f49c4ab74c9d70c9a205c1dd5853c742 /Lib | |
parent | 8a10ecc051b0932a8386050675862e98db5a5691 (diff) | |
download | cpython-b7572f08f48c4b29c137c7b62f10be9436b6efa3.zip cpython-b7572f08f48c4b29c137c7b62f10be9436b6efa3.tar.gz cpython-b7572f08f48c4b29c137c7b62f10be9436b6efa3.tar.bz2 |
Merged revisions 76636 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76636 | antoine.pitrou | 2009-12-02 21:37:54 +0100 (mer., 02 déc. 2009) | 5 lines
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.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_posix.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index f3edf33..3a40483 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -5,6 +5,7 @@ from test import support # Skip these tests if there is no posix module. posix = support.import_module('posix') +import errno import time import os import pwd @@ -82,6 +83,27 @@ class PosixTester(unittest.TestCase): 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)) |