本文整理汇总了Python中subprocess.Popen.set_command方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.set_command方法的具体用法?Python Popen.set_command怎么用?Python Popen.set_command使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.set_command方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_example_bad_returncode
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_example_bad_returncode(self):
# set up
Popen.set_command("svn ls -R foo", stdout=b"o", stderr=b"e", returncode=1)
# testing of error
with ShouldRaise(RuntimeError("something bad happened")):
my_func()
示例2: test_read_from_stdout_and_stderr
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_read_from_stdout_and_stderr(self):
# setup
Popen = MockPopen()
Popen.set_command('a command', stdout=b'foo', stderr=b'bar')
# usage
process = Popen('a command', stdout=PIPE, stderr=PIPE, shell=True)
compare(process.stdout.read(), b'foo')
compare(process.stderr.read(), b'bar')
示例3: test_send_signal
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_send_signal(self):
# setup
Popen = MockPopen()
Popen.set_command("a command")
# usage
process = Popen("a command", stdout=PIPE, stderr=PIPE, shell=True)
process.send_signal(0)
# result checking
compare(
[call.Popen("a command", shell=True, stderr=-1, stdout=-1), call.Popen_instance.send_signal(0)],
Popen.mock.method_calls,
)
示例4: test_wait_and_return_code
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_wait_and_return_code(self):
# setup
Popen = MockPopen()
Popen.set_command("a command", returncode=3)
# usage
process = Popen("a command")
compare(process.returncode, None)
# result checking
compare(process.wait(), 3)
compare(process.returncode, 3)
# test call list
compare([call.Popen("a command"), call.Popen_instance.wait()], Popen.mock.method_calls)
示例5: test_communicate_with_input
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_communicate_with_input(self):
# setup
Popen = MockPopen()
Popen.set_command("a command")
# usage
process = Popen("a command", stdout=PIPE, stderr=PIPE, shell=True)
out, err = process.communicate("foo")
# test call list
compare(
[call.Popen("a command", shell=True, stderr=-1, stdout=-1), call.Popen_instance.communicate("foo")],
Popen.mock.method_calls,
)
示例6: test_read_from_stdout_and_stderr
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_read_from_stdout_and_stderr(self):
# setup
Popen = MockPopen()
Popen.set_command('a command', stdout=b'foo', stderr=b'bar')
# usage
process = Popen('a command', stdout=PIPE, stderr=PIPE, shell=True)
compare(process.stdout.read(), b'foo')
compare(process.stderr.read(), b'bar')
# test call list
compare([
call.Popen('a command', shell=True, stderr=PIPE, stdout=PIPE),
], Popen.mock.method_calls)
示例7: test_write_to_stdin
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_write_to_stdin(self):
# setup
Popen = MockPopen()
Popen.set_command('a command')
# usage
process = Popen('a command', stdin=PIPE, shell=True)
process.stdin.write('some text')
process.stdin.close()
# test call list
compare([
call.Popen('a command', shell=True, stdin=PIPE),
call.Popen_instance.stdin.write('some text'),
call.Popen_instance.stdin.close(),
], Popen.mock.method_calls)
示例8: test_write_to_stdin
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_write_to_stdin(self):
# setup
Popen = MockPopen()
Popen.set_command('a command')
# usage
process = Popen('a command', stdin=PIPE, shell=True)
process.stdin.write('some text')
process.stdin.close()
# test call list
compare(Popen.all_calls, expected=[
process.root_call,
process.root_call.stdin.write('some text'),
process.root_call.stdin.close(),
])
示例9: test_poll_until_result
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_poll_until_result(self):
# setup
Popen = MockPopen()
Popen.set_command('a command', returncode=3, poll_count=2)
# example usage
process = Popen('a command')
while process.poll() is None:
# you'd probably have a sleep here, or go off and
# do some other work.
pass
# result checking
compare(process.returncode, 3)
compare([
call.Popen('a command'),
call.Popen_instance.poll(),
call.Popen_instance.poll(),
call.Popen_instance.poll(),
], Popen.mock.method_calls)
示例10: test_poll_until_result
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import set_command [as 别名]
def test_poll_until_result(self):
# setup
Popen = MockPopen()
Popen.set_command('a command', returncode=3, poll_count=2)
# example usage
process = Popen('a command')
while process.poll() is None:
# you'd probably have a sleep here, or go off and
# do some other work.
pass
# result checking
compare(process.returncode, 3)
compare(Popen.all_calls, expected=[
process.root_call,
process.root_call.poll(),
process.root_call.poll(),
process.root_call.poll(),
])