mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-19 17:14:43 +04:00
Don't UnicodeDecodeError on non-ascii not-found hooks. Resolves #207.
This commit is contained in:
parent
20c546a7da
commit
7905594215
5 changed files with 35 additions and 12 deletions
|
|
@ -105,7 +105,7 @@ def _get_commit_output(
|
|||
cmd_output('git', 'add', touch_file)
|
||||
# Don't want to write to home directory
|
||||
home = home or tmpdir_factory.get()
|
||||
env = dict(env_base, **{'PRE_COMMIT_HOME': home})
|
||||
env = dict(env_base, PRE_COMMIT_HOME=home)
|
||||
return cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!', '--allow-empty',
|
||||
# git commit puts pre-commit to stderr
|
||||
|
|
@ -414,7 +414,7 @@ def test_installed_from_venv(tmpdir_factory):
|
|||
def _get_push_output(tmpdir_factory):
|
||||
# Don't want to write to home directory
|
||||
home = tmpdir_factory.get()
|
||||
env = dict(os.environ, **{'PRE_COMMIT_HOME': home})
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=home)
|
||||
return cmd_output(
|
||||
'git', 'push', 'origin', 'HEAD:new_branch',
|
||||
# git commit puts pre-commit to stderr
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import io
|
|||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
|
@ -274,6 +275,22 @@ def test_multiple_hooks_same_id(
|
|||
assert output.count('Bash hook') == 2
|
||||
|
||||
|
||||
def test_non_ascii_hook_id(
|
||||
repo_with_passing_hook, mock_out_store_directory, tmpdir_factory,
|
||||
):
|
||||
with cwd(repo_with_passing_hook):
|
||||
install(Runner(repo_with_passing_hook))
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
_, stdout, _ = cmd_output(
|
||||
sys.executable, '-m', 'pre_commit.main', 'run', '☃',
|
||||
env=env, retcode=None,
|
||||
)
|
||||
assert 'UnicodeDecodeError' not in stdout
|
||||
# Doesn't actually happen, but a reasonable assertion
|
||||
assert 'UnicodeEncodeError' not in stdout
|
||||
|
||||
|
||||
def test_stdout_write_bug_py26(
|
||||
repo_with_failing_hook, mock_out_store_directory, tmpdir_factory,
|
||||
):
|
||||
|
|
@ -289,7 +306,7 @@ def test_stdout_write_bug_py26(
|
|||
install(Runner(repo_with_failing_hook))
|
||||
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, **{'PRE_COMMIT_HOME': tmpdir_factory.get()})
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
# Have to use subprocess because pytest monkeypatches sys.stdout
|
||||
_, stdout, _ = cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!',
|
||||
|
|
@ -329,7 +346,7 @@ def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
|
|||
install(Runner(git_path))
|
||||
|
||||
# Don't want to write to home directory
|
||||
env = dict(os.environ, **{'PRE_COMMIT_HOME': tmpdir_factory.get()})
|
||||
env = dict(os.environ, PRE_COMMIT_HOME=tmpdir_factory.get())
|
||||
cmd_output(
|
||||
'git', 'commit', '-m', 'Commit!',
|
||||
# git commit puts pre-commit to stderr
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue