2017-11-26 16:37:00 +00:00
|
|
|
import sys
|
2017-12-22 10:54:30 +00:00
|
|
|
import pytest
|
|
|
|
from pydu.platform import WINDOWS
|
2017-11-26 16:37:00 +00:00
|
|
|
from pydu.compat import string_types
|
2017-11-07 00:29:17 +00:00
|
|
|
from pydu.string import safeunicode
|
2017-11-26 16:37:00 +00:00
|
|
|
from pydu.cmd import run, cmdline_argv
|
2017-11-07 00:29:17 +00:00
|
|
|
|
|
|
|
|
2017-12-21 12:33:07 +00:00
|
|
|
def test_run():
|
2017-11-26 16:37:00 +00:00
|
|
|
retcode, output = run('echo hello')
|
2017-11-07 00:29:17 +00:00
|
|
|
assert retcode == 0
|
|
|
|
assert safeunicode(output).rstrip('\r\n') == 'hello'
|
|
|
|
|
2017-11-26 16:37:00 +00:00
|
|
|
p = run('echo hello', wait=False)
|
2017-11-07 00:29:17 +00:00
|
|
|
assert p.wait() == 0
|
2017-11-06 15:41:51 +00:00
|
|
|
|
2017-11-26 16:37:00 +00:00
|
|
|
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-06 15:41:51 +00:00
|
|
|
|
2017-11-07 00:15:05 +00:00
|
|
|
def test_cmdline_argv():
|
|
|
|
argv = cmdline_argv()
|
2017-11-06 15:41:51 +00:00
|
|
|
for s in argv[1:]:
|
2017-11-26 16:37:00 +00:00
|
|
|
assert isinstance(s, string_types)
|
2017-12-22 10:54:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not WINDOWS, reason='Not support non windows')
|
|
|
|
def test_chcp():
|
|
|
|
from pydu.cmd import chcp
|
|
|
|
from ctypes import windll
|
|
|
|
|
|
|
|
origin_code = windll.kernel32.GetConsoleOutputCP()
|
|
|
|
with chcp(437):
|
|
|
|
assert windll.kernel32.GetConsoleOutputCP() == 437
|
|
|
|
assert windll.kernel32.GetConsoleOutputCP() == origin_code
|
|
|
|
|
|
|
|
try:
|
|
|
|
chcp(437)
|
|
|
|
assert windll.kernel32.GetConsoleOutputCP() == 437
|
|
|
|
finally:
|
|
|
|
windll.kernel32.SetConsoleOutputCP(origin_code)
|