From 24104f933ccc86ca5646d18ed03c611737e09232 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 13 Sep 2019 12:54:44 +0100 Subject: [PATCH 1/3] bpo-36046: Fix buildbot failures from the PR. varying user/group/permission check needs on platforms. --- Lib/test/test_subprocess.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index f107022d86a0ff..6a1f2b7cee5072 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1762,8 +1762,10 @@ def test_user(self): [sys.executable, "-c", "import os; print(os.getuid())"], user=user) + except PermissionError: # errno.EACCES + pass except OSError as e: - if e.errno != errno.EPERM: + if e.errno not in (errno.EACCES, errno.EPERM): raise else: if isinstance(user, str): @@ -1789,7 +1791,15 @@ def test_user_error(self): def test_group(self): gid = os.getegid() group_list = [65534 if gid != 65534 else 65533] - name_group = "nogroup" if sys.platform != 'darwin' else "staff" + for name_group in ('staff', 'nogroup', 'grp'): + if grp: + try: + grp.getgrnam(name_group) + except KeyError: + continue + break + else: + raise unittest.SkipTest('No identified group name to use for this test on this platform.') if grp is not None: group_list.append(name_group) @@ -1830,7 +1840,15 @@ def test_group_error(self): def test_extra_groups(self): gid = os.getegid() group_list = [65534 if gid != 65534 else 65533] - name_group = "nogroup" if sys.platform != 'darwin' else "staff" + for name_group in ('staff', 'nogroup', 'grp'): + if grp: + try: + grp.getgrnam(name_group) + except KeyError: + continue + break + else: + raise unittest.SkipTest('No identified group name to use for this test on this platform.') perm_error = False if grp is not None: From 0f1d214c41c8ad645f85239951aadd2a3c98228d Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 13 Sep 2019 14:01:44 +0100 Subject: [PATCH 2/3] Refactor the group finding code into a fn. --- Lib/test/test_subprocess.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 6a1f2b7cee5072..4d878b0477f690 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1787,20 +1787,24 @@ def test_user_error(self): with self.assertRaises(ValueError): subprocess.check_call([sys.executable, "-c", "pass"], user=65535) - @unittest.skipUnless(hasattr(os, 'setregid'), 'no setregid() on platform') - def test_group(self): - gid = os.getegid() - group_list = [65534 if gid != 65534 else 65533] + @staticmethod + def _get_test_grp_name(): for name_group in ('staff', 'nogroup', 'grp'): if grp: try: grp.getgrnam(name_group) except KeyError: continue - break + return name_group else: raise unittest.SkipTest('No identified group name to use for this test on this platform.') + @unittest.skipUnless(hasattr(os, 'setregid'), 'no setregid() on platform') + def test_group(self): + gid = os.getegid() + group_list = [65534 if gid != 65534 else 65533] + name_group = self._get_test_grp_name() + if grp is not None: group_list.append(name_group) @@ -1840,15 +1844,7 @@ def test_group_error(self): def test_extra_groups(self): gid = os.getegid() group_list = [65534 if gid != 65534 else 65533] - for name_group in ('staff', 'nogroup', 'grp'): - if grp: - try: - grp.getgrnam(name_group) - except KeyError: - continue - break - else: - raise unittest.SkipTest('No identified group name to use for this test on this platform.') + name_group = self._get_test_grp_name() perm_error = False if grp is not None: From eccde64084fd46f69486deee975dc55c1a492820 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 13 Sep 2019 14:22:33 +0100 Subject: [PATCH 3/3] byebye staticmethod! --- Lib/test/test_subprocess.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 4d878b0477f690..42f376cda5d27a 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -1588,6 +1588,18 @@ def test_run_with_shell_timeout_and_capture_output(self): f"{stacks}```") +def _get_test_grp_name(): + for name_group in ('staff', 'nogroup', 'grp'): + if grp: + try: + grp.getgrnam(name_group) + except KeyError: + continue + return name_group + else: + raise unittest.SkipTest('No identified group name to use for this test on this platform.') + + @unittest.skipIf(mswindows, "POSIX specific tests") class POSIXProcessTestCase(BaseTestCase): @@ -1787,23 +1799,11 @@ def test_user_error(self): with self.assertRaises(ValueError): subprocess.check_call([sys.executable, "-c", "pass"], user=65535) - @staticmethod - def _get_test_grp_name(): - for name_group in ('staff', 'nogroup', 'grp'): - if grp: - try: - grp.getgrnam(name_group) - except KeyError: - continue - return name_group - else: - raise unittest.SkipTest('No identified group name to use for this test on this platform.') - @unittest.skipUnless(hasattr(os, 'setregid'), 'no setregid() on platform') def test_group(self): gid = os.getegid() group_list = [65534 if gid != 65534 else 65533] - name_group = self._get_test_grp_name() + name_group = _get_test_grp_name() if grp is not None: group_list.append(name_group) @@ -1844,7 +1844,7 @@ def test_group_error(self): def test_extra_groups(self): gid = os.getegid() group_list = [65534 if gid != 65534 else 65533] - name_group = self._get_test_grp_name() + name_group = _get_test_grp_name() perm_error = False if grp is not None: