Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-28624: Add test for subprocess to check that cmd arg supports PathLike #157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Doc/library/subprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path-like object>` object. In particular, the function
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you only mention string and PathLike, how about bytes? Is it acceptable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test for bytes too and it's seems to be passing too. Also updated the docs.

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.
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ Albert Chin-A-Young
Adal Chiriliuc
Matt Chisholm
Lita Cho
Sayan Chowdhury
Anders Chrigström
Tom Christiansen
Renee Chu
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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.

- bpo-28518: Start a transaction implicitly before a DML statement.
Patch by Aviv Palivoda.

Expand Down