1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
# coding=utf-8
import re
import pytest
xfail = pytest.mark.xfail
def test_unicode_roundtrip(protocol_real):
shell_id = protocol_real.open_shell(codepage=65001)
command_id = protocol_real.run_command(shell_id, "PowerShell", arguments=["-Command", "Write-Host", "こんにちは"])
try:
std_out, std_err, status_code = protocol_real.get_command_output(shell_id, command_id)
assert status_code == 0
assert len(std_err) == 0
# std_out will be returned as UTF-8, but PEP8 won't let us store a
# UTF-8 string literal, so we'll convert it on the fly
assert std_out == ("こんにちは\n".encode("utf-8"))
finally:
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
def test_open_shell_and_close_shell(protocol_real):
shell_id = protocol_real.open_shell()
assert re.match(r"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", shell_id)
protocol_real.close_shell(shell_id)
def test_run_command_with_arguments_and_cleanup_command(protocol_real):
shell_id = protocol_real.open_shell()
command_id = protocol_real.run_command(shell_id, "ipconfig", ["/all"])
assert re.match(r"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", command_id)
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
def test_run_command_without_arguments_and_cleanup_command(protocol_real):
shell_id = protocol_real.open_shell()
command_id = protocol_real.run_command(shell_id, "hostname")
assert re.match(r"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", command_id)
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
def test_run_command_with_env(protocol_real):
shell_id = protocol_real.open_shell(env_vars=dict(TESTENV1="hi mom", TESTENV2="another var"))
command_id = protocol_real.run_command(shell_id, "echo", ["%TESTENV1%", "%TESTENV2%"])
std_out, std_err, status_code = protocol_real.get_command_output(shell_id, command_id)
assert re.search(b"hi mom another var", std_out)
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
def test_get_command_output(protocol_real):
shell_id = protocol_real.open_shell()
command_id = protocol_real.run_command(shell_id, "ipconfig", ["/all"])
std_out, std_err, status_code = protocol_real.get_command_output(shell_id, command_id)
assert status_code == 0
assert b"Windows IP Configuration" in std_out
assert len(std_err) == 0
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
def test_run_command_taking_more_than_operation_timeout_sec(protocol_real):
shell_id = protocol_real.open_shell()
command_id = protocol_real.run_command(shell_id, "PowerShell -Command Start-Sleep -s {0}".format(protocol_real.operation_timeout_sec * 2))
assert re.match(r"^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$", command_id)
std_out, std_err, status_code = protocol_real.get_command_output(shell_id, command_id)
assert status_code == 0
assert len(std_err) == 0
protocol_real.cleanup_command(shell_id, command_id)
protocol_real.close_shell(shell_id)
@xfail()
def test_set_timeout(protocol_real):
raise NotImplementedError()
@xfail()
def test_set_max_env_size(protocol_real):
raise NotImplementedError()
@xfail()
def test_set_locale(protocol_real):
raise NotImplementedError()
|