提交 fe793722 编写于 作者: C Chris Jerdonek

Fix a couple spinner edge cases.

上级 ffefa91f
The spinner no longer displays a completion message after subprocess calls
not needing a spinner. It also no longer incorrectly reports an error after
certain subprocess calls to Git that succeeded.
......@@ -705,6 +705,10 @@ def call_subprocess(
stdout = None
else:
stdout = subprocess.PIPE
# Only use the spinner when we're capturing stdout and we have one.
use_spinner = not show_stdout and spinner is not None
if command_desc is None:
command_desc = format_command_args(cmd)
......@@ -738,19 +742,22 @@ def call_subprocess(
logger.debug(line)
else:
# Update the spinner
if spinner is not None:
if use_spinner:
spinner.spin()
try:
proc.wait()
finally:
if proc.stdout:
proc.stdout.close()
if spinner is not None:
if proc.returncode:
proc_had_error = (
proc.returncode and proc.returncode not in extra_ok_returncodes
)
if use_spinner:
if proc_had_error:
spinner.finish("error")
else:
spinner.finish("done")
if proc.returncode and proc.returncode not in extra_ok_returncodes:
if proc_had_error:
if on_returncode == 'raise':
if (logger.getEffectiveLevel() > std_logging.DEBUG and
not show_stdout):
......
......@@ -925,7 +925,7 @@ class TestCallSubprocess(object):
# output is already being written to the console.
self.check_result(
capfd, caplog, log_level, spinner, result, expected,
expected_spinner=(0, 'done'),
expected_spinner=(0, None),
)
@pytest.mark.parametrize((
......@@ -936,13 +936,13 @@ class TestCallSubprocess(object):
# Test some cases that should result in show_spinner false.
(0, False, None, logging.DEBUG, (None, 'done', 0)),
# Test show_stdout=True.
(0, True, None, logging.DEBUG, (None, 'done', 0)),
(0, True, None, logging.INFO, (None, 'done', 0)),
(0, True, None, logging.WARNING, (None, 'done', 0)),
(0, True, None, logging.DEBUG, (None, None, 0)),
(0, True, None, logging.INFO, (None, None, 0)),
(0, True, None, logging.WARNING, (None, None, 0)),
# Test a non-zero exit status.
(3, False, None, logging.INFO, (InstallationError, 'error', 2)),
# Test a non-zero exit status also in extra_ok_returncodes.
(3, False, (3, ), logging.INFO, (None, 'error', 2)),
(3, False, (3, ), logging.INFO, (None, 'done', 2)),
])
def test_spinner_finish(
self, exit_status, show_stdout, extra_ok_returncodes, log_level,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册