summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2019-10-12 20:24:56 (GMT)
committerGitHub <noreply@github.com>2019-10-12 20:24:56 (GMT)
commitf3751efb5c8b53b37efbbf75d9422c1d11c01646 (patch)
tree2e650d45ee4a530df31c2b66d9457d11e6996f33 /Lib/test/test_subprocess.py
parent8177404d520e81f16324a900f093adf3856d33f8 (diff)
downloadcpython-f3751efb5c8b53b37efbbf75d9422c1d11c01646.zip
cpython-f3751efb5c8b53b37efbbf75d9422c1d11c01646.tar.gz
cpython-f3751efb5c8b53b37efbbf75d9422c1d11c01646.tar.bz2
bpo-38417: Add umask support to subprocess (GH-16726)
On POSIX systems, allow the umask to be set in the child process before we exec.
Diffstat (limited to 'Lib/test/test_subprocess.py')
-rw-r--r--Lib/test/test_subprocess.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index 2251640..5cc324b 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1894,6 +1894,28 @@ class POSIXProcessTestCase(BaseTestCase):
with self.assertRaises(ValueError):
subprocess.check_call([sys.executable, "-c", "pass"], extra_groups=[])
+ @unittest.skipIf(mswindows or not hasattr(os, 'umask'),
+ 'POSIX umask() is not available.')
+ def test_umask(self):
+ tmpdir = None
+ try:
+ tmpdir = tempfile.mkdtemp()
+ name = os.path.join(tmpdir, "beans")
+ # We set an unusual umask in the child so as a unique mode
+ # for us to test the child's touched file for.
+ subprocess.check_call(
+ [sys.executable, "-c", f"open({name!r}, 'w')"], # touch
+ umask=0o053)
+ # Ignore execute permissions entirely in our test,
+ # filesystems could be mounted to ignore or force that.
+ st_mode = os.stat(name).st_mode & 0o666
+ expected_mode = 0o624
+ self.assertEqual(expected_mode, st_mode,
+ msg=f'{oct(expected_mode)} != {oct(st_mode)}')
+ finally:
+ if tmpdir is not None:
+ shutil.rmtree(tmpdir)
+
def test_run_abort(self):
# returncode handles signal termination
with support.SuppressCrashReport():
@@ -2950,7 +2972,7 @@ class POSIXProcessTestCase(BaseTestCase):
-1, -1, -1, -1,
1, 2, 3, 4,
True, True,
- False, [], 0,
+ False, [], 0, -1,
func)
# Attempt to prevent
# "TypeError: fork_exec() takes exactly N arguments (M given)"
@@ -2999,7 +3021,7 @@ class POSIXProcessTestCase(BaseTestCase):
-1, -1, -1, -1,
1, 2, 3, 4,
True, True,
- None, None, None,
+ None, None, None, -1,
None)
self.assertIn('fds_to_keep', str(c.exception))
finally: