diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2010-07-24 09:46:41 (GMT) |
---|---|---|
committer | Ronald Oussoren <ronaldoussoren@mac.com> | 2010-07-24 09:46:41 (GMT) |
commit | 9e7ffae537c72c361725ab7c6c8adede4eb9a8e0 (patch) | |
tree | 9d0c3cdad4a59457b972b2346935a385620df970 /Lib/test | |
parent | 8b0d84e3d56f185e70b2f862d8f5bc33d1da92b3 (diff) | |
download | cpython-9e7ffae537c72c361725ab7c6c8adede4eb9a8e0.zip cpython-9e7ffae537c72c361725ab7c6c8adede4eb9a8e0.tar.gz cpython-9e7ffae537c72c361725ab7c6c8adede4eb9a8e0.tar.bz2 |
Merged revisions 83088 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83088 | ronald.oussoren | 2010-07-23 14:53:51 +0100 (Fri, 23 Jul 2010) | 8 lines
This fixes issue7900 by adding code that deals
with the fact that getgroups(2) might return
more that MAX_GROUPS on OSX.
See the issue (and python-dev archives) for the
gory details. Summarized: OSX behaves rather oddly
and Apple says this is intentional.
........
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_posix.py | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index d2c768a..3f6e11b 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -6,6 +6,7 @@ from test import test_support posix = test_support.import_module('posix') import errno +import sys import time import os import pwd @@ -363,9 +364,59 @@ class PosixTester(unittest.TestCase): os.chdir(curdir) shutil.rmtree(base_path) + def test_getgroups(self): + with os.popen('id -G') as idg: + groups = idg.read().strip() + + if not groups: + raise unittest.SkipTest("need working 'id -G'") + + self.assertEqual([int(x) for x in groups.split()], posix.getgroups()) + +class PosixGroupsTester(unittest.TestCase): + + def setUp(self): + if posix.getuid() != 0: + raise unittest.SkipTest("not enough privileges") + if not hasattr(posix, 'getgroups'): + raise unittest.SkipTest("need posix.getgroups") + if sys.platform == 'darwin': + raise unittest.SkipTest("getgroups(2) is broken on OSX") + self.saved_groups = posix.getgroups() + + def tearDown(self): + if hasattr(posix, 'setgroups'): + posix.setgroups(self.saved_groups) + elif hasattr(posix, 'initgroups'): + name = pwd.getpwuid(posix.getuid()).pw_name + posix.initgroups(name, self.saved_groups[0]) + + @unittest.skipUnless(hasattr(posix, 'initgroups'), + "test needs posix.initgroups()") + def test_initgroups(self): + # find missing group + + groups = sorted(self.saved_groups) + for g1,g2 in zip(groups[:-1], groups[1:]): + g = g1 + 1 + if g < g2: + break + else: + g = g2 + 1 + name = pwd.getpwuid(posix.getuid()).pw_name + posix.initgroups(name, g) + self.assertIn(g, posix.getgroups()) + + @unittest.skipUnless(hasattr(posix, 'setgroups'), + "test needs posix.setgroups()") + def test_setgroups(self): + for groups in [[0], range(16)]: + posix.setgroups(groups) + self.assertListEqual(groups, posix.getgroups()) + def test_main(): - test_support.run_unittest(PosixTester) + test_support.run_unittest(PosixTester, PosixGroupsTester) if __name__ == '__main__': test_main() |