fix(keyringctl): fix system stderr case due to wrongly written test

CalledProcessError returns bytes for our invocations, the fix that
decoded bytes of stdout was purely to make the mocked test happy while
breaking the actual usage. Restore the behavior and fix the wrong mocked
data.
This commit is contained in:
Levente Polyak 2021-11-07 21:22:00 +01:00
parent cd585f4be2
commit 279765b22a
No known key found for this signature in database
GPG Key ID: FC1B547C8D8172C8
2 changed files with 2 additions and 2 deletions

View File

@ -115,7 +115,7 @@ def system(
try: try:
return check_output(cmd, stderr=STDOUT, stdin=_stdin, env=env).decode() return check_output(cmd, stderr=STDOUT, stdin=_stdin, env=env).decode()
except CalledProcessError as e: except CalledProcessError as e:
stderr.buffer.write(bytes(e.stdout, encoding="utf8")) stderr.buffer.write(e.stdout)
print_stack() print_stack()
if exit_on_error: if exit_on_error:
exit(e.returncode) exit(e.returncode)

View File

@ -50,7 +50,7 @@ def test_natural_sort_path(input_list: List[Path], output_list: List[Path]) -> N
@patch("libkeyringctl.util.check_output") @patch("libkeyringctl.util.check_output")
def test_system(check_output_mock: Mock, exit_mock: Mock, raise_on_cmd: bool, exit_on_error: bool) -> None: def test_system(check_output_mock: Mock, exit_mock: Mock, raise_on_cmd: bool, exit_on_error: bool) -> None:
if raise_on_cmd: if raise_on_cmd:
check_output_mock.side_effect = util.CalledProcessError(returncode=1, cmd="foo", output="output") check_output_mock.side_effect = util.CalledProcessError(returncode=1, cmd="foo", output=b"output")
with raises(util.CalledProcessError): with raises(util.CalledProcessError):
util.system(["foo"], exit_on_error=exit_on_error) util.system(["foo"], exit_on_error=exit_on_error)