]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #14698: Make test_posix more robust when the current UID doesn't have an
authorCharles-François Natali <neologix@free.fr>
Wed, 2 May 2012 18:04:40 +0000 (20:04 +0200)
committerCharles-François Natali <neologix@free.fr>
Wed, 2 May 2012 18:04:40 +0000 (20:04 +0200)
associated pwd entry.

1  2 
Lib/test/test_posix.py

index 142dddd09b6238e4a304a7f5c393c62c627cddb6,26b8d81a643629c9af057f24a7e5aaa9a2a9f739..5ed2a0ffc514203cc27eaf73872d9ea644306983
@@@ -618,21 -421,6 +622,22 @@@ class PosixTester(unittest.TestCase)
                  os.chdir(curdir)
                  support.rmtree(base_path)
  
-         if not groups:
 +    @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()
++            ret = idg.close()
 +
++        if ret != 0 or 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: