mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Merge pull request #183 from bukzor/error-output-blovinates
improve output in error case
This commit is contained in:
commit
3387edbb12
2 changed files with 27 additions and 3 deletions
|
|
@ -108,15 +108,23 @@ class CalledProcessError(RuntimeError):
|
||||||
self.output = output
|
self.output = output
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
output = []
|
||||||
|
for text in self.output:
|
||||||
|
if text:
|
||||||
|
output.append('\n ' + text.replace('\n', '\n '))
|
||||||
|
else:
|
||||||
|
output.append('(none)')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
'Command: {0!r}\n'
|
'Command: {0!r}\n'
|
||||||
'Return code: {1}\n'
|
'Return code: {1}\n'
|
||||||
'Expected return code: {2}\n'
|
'Expected return code: {2}\n'
|
||||||
'Output: {3!r}\n'.format(
|
'Output: {3}\n'
|
||||||
|
'Errors: {4}\n'.format(
|
||||||
self.cmd,
|
self.cmd,
|
||||||
self.returncode,
|
self.returncode,
|
||||||
self.expected_returncode,
|
self.expected_returncode,
|
||||||
self.output,
|
*output
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,23 @@ def test_CalledProcessError_str():
|
||||||
"Command: ['git', 'status']\n"
|
"Command: ['git', 'status']\n"
|
||||||
"Return code: 1\n"
|
"Return code: 1\n"
|
||||||
"Expected return code: 0\n"
|
"Expected return code: 0\n"
|
||||||
"Output: ('stdout', 'stderr')\n"
|
"Output: \n"
|
||||||
|
" stdout\n"
|
||||||
|
"Errors: \n"
|
||||||
|
" stderr\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_CalledProcessError_str_nooutput():
|
||||||
|
error = CalledProcessError(
|
||||||
|
1, [str('git'), str('status')], 0, (str(''), str(''))
|
||||||
|
)
|
||||||
|
assert str(error) == (
|
||||||
|
"Command: ['git', 'status']\n"
|
||||||
|
"Return code: 1\n"
|
||||||
|
"Expected return code: 0\n"
|
||||||
|
"Output: (none)\n"
|
||||||
|
"Errors: (none)\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue