fix trailing whitespace in CalledProcessError output

This commit is contained in:
Anthony Sottile 2023-02-21 12:42:09 -05:00
parent 192be6079b
commit 4ded56efac
3 changed files with 3 additions and 5 deletions

View file

@ -62,7 +62,7 @@ class CalledProcessError(RuntimeError):
def __bytes__(self) -> bytes:
def _indent_or_none(part: bytes | None) -> bytes:
if part:
return b'\n ' + part.replace(b'\n', b'\n ')
return b'\n ' + part.replace(b'\n', b'\n ').rstrip()
else:
return b' (none)'

View file

@ -425,9 +425,7 @@ def test_failed_diff_does_not_discard_changes(in_git_dir, patch_dir):
r'stdout: \(none\)\n'
r'stderr:\n'
r' error: open\("1"\): Permission denied\n'
r' fatal: cannot hash 1\n'
# TODO: not sure why there's weird whitespace here
r' $',
r' fatal: cannot hash 1$',
).assert_matches(msg)
# even though it errored, the unstaged changes should still be present

View file

@ -16,7 +16,7 @@ from pre_commit.util import rmtree
def test_CalledProcessError_str():
error = CalledProcessError(1, ('exe',), b'output', b'errors')
error = CalledProcessError(1, ('exe',), b'output\n', b'errors\n')
assert str(error) == (
"command: ('exe',)\n"
'return code: 1\n'