Fix up some newlines in output

This commit is contained in:
Anthony Sottile
2019-09-24 09:32:10 -07:00
parent cfc4910068
commit 795506a486
4 changed files with 39 additions and 36 deletions

View File

@@ -30,42 +30,39 @@ def _log_and_exit(msg, exc, formatted):
error_msg = b''.join((
five.to_bytes(msg), b': ',
five.to_bytes(type(exc).__name__), b': ',
_to_bytes(exc), b'\n',
_to_bytes(exc),
))
output.write(error_msg)
output.write_line(error_msg)
store = Store()
log_path = os.path.join(store.directory, 'pre-commit.log')
output.write_line('Check the log at {}'.format(log_path))
with open(log_path, 'wb') as log:
output.write_line(
'### version information\n```', stream=log,
)
output.write_line(
'pre-commit.version: {}'.format(C.VERSION), stream=log,
)
output.write_line(
'sys.version:\n{}'.format(
'\n'.join(
[
' {}'.format(line)
for line in sys.version.splitlines()
],
),
),
stream=log,
)
output.write_line(
'sys.executable: {}'.format(sys.executable), stream=log,
)
output.write_line('os.name: {}'.format(os.name), stream=log)
output.write_line(
'sys.platform: {}\n```'.format(sys.platform), stream=log,
)
output.write_line('### error information\n```', stream=log)
output.write(error_msg, stream=log)
output.write_line(formatted, stream=log)
output.write('\n```\n', stream=log)
def _log_line(*s): # type: (*str) -> None
output.write_line(*s, stream=log)
_log_line('### version information')
_log_line()
_log_line('```')
_log_line('pre-commit version: {}'.format(C.VERSION))
_log_line('sys.version:')
for line in sys.version.splitlines():
_log_line(' {}'.format(line))
_log_line('sys.executable: {}'.format(sys.executable))
_log_line('os.name: {}'.format(os.name))
_log_line('sys.platform: {}'.format(sys.platform))
_log_line('```')
_log_line()
_log_line('### error information')
_log_line()
_log_line('```')
_log_line(error_msg)
_log_line('```')
_log_line()
_log_line('```')
_log_line(formatted)
_log_line('```')
raise SystemExit(1)

View File

@@ -103,7 +103,7 @@ class CalledProcessError(RuntimeError):
),
),
b'Output: ', output[0], b'\n',
b'Errors: ', output[1], b'\n',
b'Errors: ', output[1],
))
def to_text(self):

View File

@@ -113,19 +113,25 @@ def test_log_and_exit(cap_out, mock_store_dir):
logged = f.read()
expected = (
r'^### version information\n'
r'\n'
r'```\n'
r'pre-commit.version: \d+\.\d+\.\d+\n'
r'sys.version:\n( .*\n)*'
r'pre-commit version: \d+\.\d+\.\d+\n'
r'sys.version:\n'
r'( .*\n)*'
r'sys.executable: .*\n'
r'os.name: .*\n'
r'sys.platform: .*\n'
r'```\n'
r'\n'
r'### error information\n'
r'\n'
r'```\n'
r'msg: FatalError: hai\n'
r"I'm a stacktrace\n"
r'```\n'
r'\n'
r'```\n'
r"I'm a stacktrace\n"
r'```\n'
)
assert re.match(expected, logged)

View File

@@ -24,7 +24,7 @@ def test_CalledProcessError_str():
'Output: \n'
' stdout\n'
'Errors: \n'
' stderr\n'
' stderr'
)
@@ -37,7 +37,7 @@ def test_CalledProcessError_str_nooutput():
'Return code: 1\n'
'Expected return code: 0\n'
'Output: (none)\n'
'Errors: (none)\n'
'Errors: (none)'
)