Skip to content

Commit e838522

Browse files
committed
pass pathlib.Path objects through on Python 3.7+
subprocess cwd= parameter supports path-like objects on all platforms from 3.7 onwards
1 parent 48ca117 commit e838522

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

procrunner/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,13 @@ def run(
496496
command = tuple(_path_resolve(part) for part in command)
497497
if win32resolve and sys.platform == "win32":
498498
command = _windows_resolve(command)
499+
if working_directory and sys.version_info < (3, 7):
500+
working_directory = os.fspath(working_directory)
499501

500502
p = subprocess.Popen(
501503
command,
502504
shell=False,
503-
cwd=_path_resolve(working_directory),
505+
cwd=working_directory,
504506
env=env,
505507
stdin=stdin_pipe,
506508
stdout=subprocess.PIPE,

tests/test_procrunner.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import mock
33
import os
4+
import pathlib
45
import procrunner
56
import pytest
67
import sys
@@ -87,13 +88,16 @@ def streamreader_processing(*args, **kwargs):
8788
False,
8889
callback_stdout=mock.sentinel.callback_stdout,
8990
callback_stderr=mock.sentinel.callback_stderr,
90-
working_directory=mock.sentinel.cwd,
91+
working_directory=pathlib.Path("somecwd"),
9192
raise_timeout_exception=True,
9293
)
9394

9495
assert mock_subprocess.Popen.called
9596
assert mock_subprocess.Popen.call_args[1]["env"] == os.environ
96-
assert mock_subprocess.Popen.call_args[1]["cwd"] == mock.sentinel.cwd
97+
assert mock_subprocess.Popen.call_args[1]["cwd"] in (
98+
pathlib.Path("somecwd"),
99+
"somecwd",
100+
)
97101
mock_streamreader.assert_has_calls(
98102
[
99103
mock.call(

0 commit comments

Comments
 (0)