Skip to content

Commit

Permalink
Fix further case of Path vs MockPopen
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Oct 20, 2023
1 parent 7648eca commit ed32ea4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion testfixtures/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def shell_join(command: Command) -> str:
elif isinstance(command, Iterable):
quoted_parts = []
for part in command:
if not isinstance(part, str):
if isinstance(part, PathLike):
part = str(part)
elif not isinstance(part, str):
raise TypeError(f'{part!r} in {command} was {type(part)}, must be str')
quoted_parts.append(shlex.quote(part))
return " ".join(quoted_parts)
Expand Down
12 changes: 12 additions & 0 deletions testfixtures/tests/test_popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def test_command_is_incorrect_type(self):
with ShouldRaise(TypeError("42 was <class 'int'>, must be str")):
Popen(42)

def test_command_is_sequence_of_pathlike(self):
Popen = MockPopen()
Popen.set_command('a command')

process = Popen(['a', Path('command')])

compare(process.wait(), 0)
compare([
call.Popen(['a', Path('command')]),
call.Popen_instance.wait(),
], Popen.mock.method_calls)

def test_command_is_sequence_of_incorrect_type(self):
Popen = MockPopen()
Popen.set_command('a command')
Expand Down

0 comments on commit ed32ea4

Please sign in to comment.