From 3370e0b0ff40fe775904c2553c0a7a4ca92cd1e6 Mon Sep 17 00:00:00 2001 From: Sayan Chowdhury Date: Sun, 19 Feb 2017 16:12:09 +0530 Subject: [PATCH 1/2] bpo-28624: Add test for Popen to check that cmd arg supports PathLike Signed-off-by: Sayan Chowdhury --- Doc/library/subprocess.rst | 10 +++++++--- Lib/test/test_subprocess.py | 10 ++++++++++ Misc/ACKS | 1 + Misc/NEWS | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index e9ba15eec1c20b..d0b2f9bff96b05 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -466,9 +466,13 @@ functions. The *pass_fds* parameter was added. If *cwd* is not ``None``, the function changes the working directory to - *cwd* before executing the child. In particular, the function looks for - *executable* (or for the first item in *args*) relative to *cwd* if the - executable path is a relative path. + *cwd* before executing the child. *cwd* can be a :class:`str` and + :term:`path-like ` object. In particular, the function + looks for *executable* (or for the first item in *args*) relative to *cwd* + if the executable path is a relative path. + + .. versionchanged:: 3.6 + *cwd* parameter accepts a :term:`path-like object`. If *restore_signals* is true (the default) all signals that Python has set to SIG_IGN are restored to SIG_DFL in the child process before the exec. diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 812e7bf2cc8a72..8511207f0d6fa5 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -347,6 +347,16 @@ def test_cwd(self): temp_dir = self._normalize_cwd(temp_dir) self._assert_cwd(temp_dir, sys.executable, cwd=temp_dir) + def test_cwd_with_pathlike(self): + temp_dir = tempfile.gettempdir() + temp_dir = self._normalize_cwd(temp_dir) + + class _PathLikeObj: + def __fspath__(self): + return temp_dir + + self._assert_cwd(temp_dir, sys.executable, cwd=_PathLikeObj()) + @unittest.skipIf(mswindows, "pending resolution of issue #15533") def test_cwd_with_relative_arg(self): # Check that Popen looks for args[0] relative to cwd if args[0] diff --git a/Misc/ACKS b/Misc/ACKS index 1995adb371e970..b7f1282c69c0ce 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -269,6 +269,7 @@ Albert Chin-A-Young Adal Chiriliuc Matt Chisholm Lita Cho +Sayan Chowdhury Anders Chrigström Tom Christiansen Renee Chu diff --git a/Misc/NEWS b/Misc/NEWS index 4413c511157fcd..f3611e8629a904 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -917,6 +917,9 @@ Core and Builtins Library ------- +- Issue #28624: Make the `cwd` argument to `subprocess.Popen` accept a + `PathLike`. + - Issue #29085: Allow random.Random.seed() to use high quality OS randomness rather than the pid and time. From 0b2c42bfeb439dde7ff8304afe03b4c633dca2cd Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sun, 26 Feb 2017 19:00:19 +0300 Subject: [PATCH 2/2] Move NEWS entry --- Misc/NEWS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index f3611e8629a904..32126fd3e3f692 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -249,6 +249,9 @@ Extension Modules Library ------- +- bpo-28624: Add a test that checks that cwd parameter of Popen() accepts + PathLike objects. Patch by Sayan Chowdhury. + - Issue #16285: urrlib.parse.quote is now based on RFC 3986 and hence includes '~' in the set of characters that is not quoted by default. Patch by Christian Theune and Ratnadeep Debnath. @@ -917,9 +920,6 @@ Core and Builtins Library ------- -- Issue #28624: Make the `cwd` argument to `subprocess.Popen` accept a - `PathLike`. - - Issue #29085: Allow random.Random.seed() to use high quality OS randomness rather than the pid and time.