Skip to content

Commit

Permalink
Add support for Path from pathlib in CmdAction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinidu committed Nov 22, 2015
1 parent 5809881 commit 8b2e53a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions doit/action.py
Expand Up @@ -214,15 +214,17 @@ def execute(self, out=None, err=None):


def expand_action(self):
"""expand action string using task meta informations
@returns (string) - expanded string after substitution
"""Expand action using task meta informations if action is a string.
Convert `Path` elements to `str` if action is a list.
@returns: string -> expanded string if action is a string
list - string -> expanded list of command elements
"""
if not self.task:
return self.action

# cant expand keywords if action is a list of strings
if isinstance(self.action, list):
return self.action
return [str(x) for x in self.action]

subs_dict = {'targets' : " ".join(self.task.targets),
'dependencies': " ".join(self.task.file_dep)}
Expand Down
7 changes: 7 additions & 0 deletions tests/test_action.py
Expand Up @@ -4,6 +4,7 @@
import textwrap
import locale
locale # quiet pyflakes
from pathlib import PurePath, Path

from io import StringIO, BytesIO
import pytest
Expand Down Expand Up @@ -222,6 +223,12 @@ def test_string_list_cant_be_expanded(self):
my_action = action.CmdAction(cmd, task)
assert cmd == my_action.expand_action()

def test_list_can_contain_path(self):
cmd = ["python", PurePath(TEST_PATH), Path("myecho.py")]
task = FakeTask([], [], [], {})
my_action = action.CmdAction(cmd, task)
assert ["python", TEST_PATH, "myecho.py"] == my_action.expand_action()


class TestCmd_print_process_output(object):
def test_non_unicode_string_error_strict(self):
Expand Down

0 comments on commit 8b2e53a

Please sign in to comment.