本文整理汇总了Python中subprocess.CalledProcessError.stderr方法的典型用法代码示例。如果您正苦于以下问题:Python CalledProcessError.stderr方法的具体用法?Python CalledProcessError.stderr怎么用?Python CalledProcessError.stderr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.CalledProcessError
的用法示例。
在下文中一共展示了CalledProcessError.stderr方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fails_on_non_expected_exception
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def test_fails_on_non_expected_exception(self):
mock_client = _get_time_noop_mock_client()
exp = CalledProcessError(-1, 'blah')
exp.stderr = '"" is not a valid tag'
controller_client = Mock()
controller_client.get_models.side_effect = [exp]
mock_client.get_controller_client.return_value = controller_client
with self.assertRaises(CalledProcessError):
amm.wait_until_model_disappears(
mock_client, 'test_model', timeout=60)
示例2: check_output
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def check_output(run_args, *args, **kwargs):
kwargs['stdout'] = PIPE
kwargs['stderr'] = PIPE
process = Popen(run_args, *args, **kwargs)
stdout, stderr = process.communicate()
retcode = process.poll()
if retcode is not 0:
exception = CalledProcessError(retcode, run_args[0])
exception.stdout = stdout
exception.stderr = stderr
raise exception
return stdout, stderr
示例3: check_call_capturing
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def check_call_capturing(arguments, input = None, preexec_fn = None):
"""Spawn a process and return its output."""
(stdout, stderr, code) = call_capturing(arguments, input, preexec_fn)
if code == 0:
return (stdout, stderr)
else:
from subprocess import CalledProcessError
error = CalledProcessError(code, arguments)
error.stdout = stdout
error.stderr = stderr
raise error
示例4: test_ignores_model_detail_exceptions
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def test_ignores_model_detail_exceptions(self):
"""ignore errors for model details as this might happen many times."""
mock_client = _get_time_noop_mock_client()
model_data = {'models': [{'name': ''}]}
exp = CalledProcessError(-1, 'blah')
exp.stderr = 'cannot get model details'
controller_client = Mock()
controller_client.get_models.side_effect = [
exp,
model_data]
mock_client.get_controller_client.return_value = controller_client
with patch.object(amm, 'sleep') as mock_sleep:
amm.wait_until_model_disappears(
mock_client, 'test_model', timeout=60)
mock_sleep.assert_called_once_with(1)
示例5: func
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def func(*args):
"""Wrapper function used to append arguments to command."""
cmd = [command_line]
cmd += [str(arg) for arg in args]
proc = subprocess.Popen(cmd, stderr=PIPE, stdout=PIPE)
stdout, stderr = proc.communicate()
proc.wait()
if proc.returncode:
err = CalledProcessError(
returncode=proc.returncode,
cmd=" ".join(cmd),
output=stdout,
)
err.stderr = stderr
raise err
return stdout, stderr
示例6: __submit
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def __submit(self, call, env):
output_chunks = []
process = Popen(call, env=env, stderr=STDOUT, stdout=PIPE)
while process.returncode is None:
output_chunks.append(process.communicate())
sleep(0.1)
stdout = "".join([c[0].decode('utf-8') for c in output_chunks if c[0] is not None])
stderr = "".join([c[1].decode('utf-8') for c in output_chunks if c[1] is not None])
if process.returncode == 0:
return stdout, stderr
exc = CalledProcessError(process.returncode, call)
exc.stdout = stdout
exc.stderr = stderr
print(stdout)
print(stderr)
raise exc
示例7: check_output
# 需要导入模块: from subprocess import CalledProcessError [as 别名]
# 或者: from subprocess.CalledProcessError import stderr [as 别名]
def check_output(command, cwd=None, shell=False, env=None,
stdin=__sentinel__, stderr=__sentinel__,
preexec_fn=None, use_texpath=True,
show_window=False):
'''
Takes a command to be passed to subprocess.Popen.
Returns the output if the command was successful.
By default stderr is redirected to stdout, so this will return any output
to either stream. This can be changed by calling execute_command with
stderr set to subprocess.PIPE or any other valid value.
Raises CalledProcessError if the command returned a non-zero value
Raises OSError if the executable is not found
This is pretty much identical to subprocess.check_output(), but
implemented here since it is unavailable in Python 2.6's library.
'''
returncode, stdout, stderr = execute_command(
command,
cwd=cwd,
shell=shell,
env=env,
stdin=stdin,
stderr=stderr,
preexec_fn=preexec_fn,
use_texpath=use_texpath,
show_window=show_window
)
if returncode:
e = CalledProcessError(
returncode,
command
)
e.output = stdout
e.stderr = stderr
raise e
return stdout