mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 16:24:40 +04:00
Fail gracefully on undecodable install output.
This commit is contained in:
parent
75aaadd4c4
commit
2aaaddb5cc
9 changed files with 104 additions and 24 deletions
|
|
@ -371,6 +371,33 @@ def test_stdout_write_bug_py26(
|
|||
assert 'UnicodeDecodeError' not in stdout
|
||||
|
||||
|
||||
def test_hook_install_failure(mock_out_store_directory, tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'not_installable_repo')
|
||||
with cwd(git_path):
|
||||
install(Runner(git_path))
|
||||
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tempdir_factory.get())
|
||||
_, stdout, _ = cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!',
|
||||
# git commit puts pre-commit to stderr
|
||||
stderr=subprocess.STDOUT,
|
||||
env=env,
|
||||
retcode=None,
|
||||
encoding=None,
|
||||
)
|
||||
assert b'UnicodeDecodeError' not in stdout
|
||||
# Doesn't actually happen, but a reasonable assertion
|
||||
assert b'UnicodeEncodeError' not in stdout
|
||||
|
||||
# Sanity check our output
|
||||
assert (
|
||||
b'An unexpected error has occurred: CalledProcessError: ' in
|
||||
stdout
|
||||
)
|
||||
assert '☃'.encode('UTF-8') + '²'.encode('latin1') in stdout
|
||||
|
||||
|
||||
def test_get_changed_files():
|
||||
files = get_changed_files(
|
||||
'78c682a1d13ba20e7cb735313b9314a74365cd3a',
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import mock
|
|||
import pytest
|
||||
|
||||
from pre_commit import error_handler
|
||||
from pre_commit import five
|
||||
from pre_commit.errors import FatalError
|
||||
from pre_commit.util import cmd_output
|
||||
|
||||
|
|
@ -82,7 +83,9 @@ def test_log_and_exit(mock_out_store_directory):
|
|||
write_fn=mocked_write,
|
||||
)
|
||||
|
||||
printed = ''.join(call[0][0] for call in mocked_write.call_args_list)
|
||||
printed = ''.join(
|
||||
five.to_text(call[0][0]) for call in mocked_write.call_args_list
|
||||
)
|
||||
assert printed == (
|
||||
'msg: FatalError: hai\n'
|
||||
'Check the log at ~/.pre-commit/pre-commit.log\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue