Skip to content
Closed
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
9 changes: 7 additions & 2 deletions run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@

__version__ = "0.0.8"

str_type = str if sys.version_info.major >= 3 else basestring


class std_output(str):

Expand Down Expand Up @@ -118,7 +120,7 @@ class run(runmeta('base_run', (std_output, ), {})):
@classmethod
def create_process(cls, command, stdin, cwd, env, shell):
return subprocess.Popen(
shlex.split(command),
shlex.split(command) if isinstance(command, str_type) else command,
universal_newlines=True,
shell=shell,
cwd=cwd,
Expand Down Expand Up @@ -173,7 +175,10 @@ def stderr(self):
return std_output(self.process.communicate()[1])

def __repr__(self):
return " | ".join([e.command for e in self.chain])
return " | ".join([
e.command if isinstance(e.command, str_type) else ' '.join(e.command)
for e in self.chain
])


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run(self):
setup(name='subprocess.run',
version=run.__version__,
data_files = [
(get_python_lib(), [pth_file]),
(get_python_lib(prefix=''), [pth_file]),
],
packages=find_packages(),
author='Sebastian Pawluś',
Expand Down
22 changes: 15 additions & 7 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,34 @@
# dafault _commands
class _commands:
ls = 'ls -la'
ls_list = ['ls', '-la']
rm = 'rm -r'
more = 'more'

# override _commands for windows plaftorm
if sys.platform.startswith('win'):
class _commands:
ls = 'dir'
ls_list = ['dir']
rm = 'rmdir'
more = 'more'


def test_run():
output = run(_commands.ls)
to_run = [
_commands.ls,
_commands.ls_list,
]

assert output.lines
assert output
for cmd in to_run:
output = run(cmd)

assert isinstance(output.lines, list)
assert isinstance(output.qlines, list)
assert isinstance(output.qlines[0], list)
assert output.lines
assert output

assert isinstance(output.lines, list)
assert isinstance(output.qlines, list)
assert isinstance(output.qlines[0], list)


def test_stdout():
Expand Down Expand Up @@ -108,4 +116,4 @@ def test_stdin():
"""python -c 'from run import run; print(run("wc -l", stdin=run.stdin).stdout)'"""
)

command.stdout.strip("\n") == run('ls -la', 'wc -l')
command.stdout.strip("\n") == run('ls -la', 'wc -l')