55import os
66import os .path
77import subprocess
8+ import sys
89
910import mock
1011import pytest
@@ -274,6 +275,22 @@ def test_multiple_hooks_same_id(
274275 assert output .count ('Bash hook' ) == 2
275276
276277
278+ def test_non_ascii_hook_id (
279+ repo_with_passing_hook , mock_out_store_directory , tmpdir_factory ,
280+ ):
281+ with cwd (repo_with_passing_hook ):
282+ install (Runner (repo_with_passing_hook ))
283+ # Don't want to write to home directory
284+ env = dict (os .environ , PRE_COMMIT_HOME = tmpdir_factory .get ())
285+ _ , stdout , _ = cmd_output (
286+ sys .executable , '-m' , 'pre_commit.main' , 'run' , '☃' ,
287+ env = env , retcode = None ,
288+ )
289+ assert 'UnicodeDecodeError' not in stdout
290+ # Doesn't actually happen, but a reasonable assertion
291+ assert 'UnicodeEncodeError' not in stdout
292+
293+
277294def test_stdout_write_bug_py26 (
278295 repo_with_failing_hook , mock_out_store_directory , tmpdir_factory ,
279296):
@@ -289,7 +306,7 @@ def test_stdout_write_bug_py26(
289306 install (Runner (repo_with_failing_hook ))
290307
291308 # Don't want to write to home directory
292- env = dict (os .environ , ** { ' PRE_COMMIT_HOME' : tmpdir_factory .get ()} )
309+ env = dict (os .environ , PRE_COMMIT_HOME = tmpdir_factory .get ())
293310 # Have to use subprocess because pytest monkeypatches sys.stdout
294311 _ , stdout , _ = cmd_output (
295312 'git' , 'commit' , '-m' , 'Commit!' ,
@@ -329,7 +346,7 @@ def test_lots_of_files(mock_out_store_directory, tmpdir_factory):
329346 install (Runner (git_path ))
330347
331348 # Don't want to write to home directory
332- env = dict (os .environ , ** { ' PRE_COMMIT_HOME' : tmpdir_factory .get ()} )
349+ env = dict (os .environ , PRE_COMMIT_HOME = tmpdir_factory .get ())
333350 cmd_output (
334351 'git' , 'commit' , '-m' , 'Commit!' ,
335352 # git commit puts pre-commit to stderr
0 commit comments