Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7bd1dd9

Browse files
author
Buck Golemon
committed
improve output in error case
1 parent 645838c commit 7bd1dd9

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

pre_commit/util.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,23 @@ def __init__(self, returncode, cmd, expected_returncode, output=None):
108108
self.output = output
109109

110110
def __str__(self):
111+
output = []
112+
for text in self.output:
113+
if text:
114+
output.append('\n ' + text.replace('\n', '\n '))
115+
else:
116+
output.append('(none)')
117+
111118
return (
112119
'Command: {0!r}\n'
113120
'Return code: {1}\n'
114121
'Expected return code: {2}\n'
115-
'Output: {3!r}\n'.format(
122+
'Output: {3}\n'
123+
'Errors: {4}\n'.format(
116124
self.cmd,
117125
self.returncode,
118126
self.expected_returncode,
119-
self.output,
127+
*output
120128
)
121129
)
122130

tests/prefixed_command_runner_test.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,23 @@ def test_CalledProcessError_str():
1919
"Command: ['git', 'status']\n"
2020
"Return code: 1\n"
2121
"Expected return code: 0\n"
22-
"Output: ('stdout', 'stderr')\n"
22+
"Output: \n"
23+
" stdout\n"
24+
"Errors: \n"
25+
" stderr\n"
26+
)
27+
28+
29+
def test_CalledProcessError_str_nooutput():
30+
error = CalledProcessError(
31+
1, [str('git'), str('status')], 0, (str(''), str(''))
32+
)
33+
assert str(error) == (
34+
"Command: ['git', 'status']\n"
35+
"Return code: 1\n"
36+
"Expected return code: 0\n"
37+
"Output: (none)\n"
38+
"Errors: (none)\n"
2339
)
2440

2541

0 commit comments

Comments
 (0)