removed meta from stdout; replaced = with : ; handled sys.version newlines; stylized errorlog to md

This commit is contained in:
marqueewinq
2019-09-24 15:50:07 +03:00
parent de63b6a850
commit e0155fbd66
2 changed files with 39 additions and 26 deletions

View File

@@ -104,30 +104,30 @@ def test_log_and_exit(cap_out, mock_store_dir):
printed = cap_out.get()
log_file = os.path.join(mock_store_dir, 'pre-commit.log')
printed_lines = printed.splitlines()
print(printed_lines)
assert len(printed_lines) == 7
assert printed_lines[0] == '### version information'
assert re.match(r'^pre-commit.version=\d+\.\d+\.\d+$', printed_lines[1])
assert printed_lines[2].startswith('sys.version=')
assert printed_lines[3].startswith('sys.executable=')
assert printed_lines[4] == '### error information'
assert printed_lines[5] == 'msg: FatalError: hai'
assert printed_lines[6] == 'Check the log at {}'.format(log_file)
assert printed == (
'msg: FatalError: hai\n' 'Check the log at {}\n'.format(log_file)
)
assert os.path.exists(log_file)
with io.open(log_file) as f:
logged_lines = f.read().splitlines()
assert len(logged_lines) == 7
assert printed_lines[0] == '### version information'
assert re.match(
r'^pre-commit.version=\d+\.\d+\.\d+$',
printed_lines[1],
logged = f.read()
expected = (
r'^### version information\n'
r'```\n'
r'pre-commit.version: \d+\.\d+\.\d+\n'
r'sys.version: (.*\n)*'
r'sys.executable: .*\n'
r'os.name: .*\n'
r'sys.platform: .*\n'
r'```\n'
r'### error information\n'
r'```\n'
r'msg: FatalError: hai\n'
r"I'm a stacktrace\n"
r'\n'
r'```\n'
)
assert logged_lines[2].startswith('sys.version=')
assert logged_lines[3].startswith('sys.executable=')
assert logged_lines[5] == 'msg: FatalError: hai'
assert logged_lines[6] == "I'm a stacktrace"
assert re.match(expected, logged)
def test_error_handler_non_ascii_exception(mock_store_dir):
@@ -139,7 +139,8 @@ def test_error_handler_non_ascii_exception(mock_store_dir):
def test_error_handler_no_tty(tempdir_factory):
pre_commit_home = tempdir_factory.get()
output = cmd_output_mocked_pre_commit_home(
sys.executable, '-c',
sys.executable,
'-c',
'from __future__ import unicode_literals\n'
'from pre_commit.error_handler import error_handler\n'
'with error_handler():\n'