pydu/tests/test_cmd.py

25 lines
650 B
Python
Raw Normal View History

import sys
from pydu.compat import string_types
2017-11-07 00:29:17 +00:00
from pydu.string import safeunicode
from pydu.cmd import run, cmdline_argv
2017-11-07 00:29:17 +00:00
def test_execute():
retcode, output = run('echo hello')
2017-11-07 00:29:17 +00:00
assert retcode == 0
assert safeunicode(output).rstrip('\r\n') == 'hello'
p = run('echo hello', wait=False)
2017-11-07 00:29:17 +00:00
assert p.wait() == 0
retcode, output = run('{} -c "import time; time.sleep(1)"'.format(sys.executable),
timeout=0.2, timeinterval=0.05)
assert retcode != 0
assert 'timeout' in output
2017-11-07 00:15:05 +00:00
def test_cmdline_argv():
argv = cmdline_argv()
for s in argv[1:]:
assert isinstance(s, string_types)