|
| 1 | +# -*- coding: UTF-8 -*- |
1 | 2 | from __future__ import unicode_literals |
2 | 3 |
|
3 | 4 | import io |
4 | 5 | import mock |
5 | 6 | import os |
6 | 7 | import os.path |
7 | 8 | import pytest |
| 9 | +import subprocess |
8 | 10 | from plumbum import local |
9 | 11 |
|
| 12 | +from pre_commit.commands.install_uninstall import install |
10 | 13 | from pre_commit.commands.run import _get_skips |
11 | 14 | from pre_commit.commands.run import _has_unmerged_paths |
12 | 15 | from pre_commit.commands.run import run |
@@ -225,3 +228,30 @@ def test_multiple_hooks_same_id( |
225 | 228 | ret, output = _do_run(repo_with_passing_hook, _get_opts()) |
226 | 229 | assert ret == 0 |
227 | 230 | assert output.count('Bash hook') == 2 |
| 231 | + |
| 232 | + |
| 233 | +def test_stdout_write_bug_py26( |
| 234 | + repo_with_failing_hook, mock_out_store_directory, tmpdir_factory, |
| 235 | +): |
| 236 | + with local.cwd(repo_with_failing_hook): |
| 237 | + # Add bash hook on there again |
| 238 | + with io.open('.pre-commit-config.yaml', 'a+') as config_file: |
| 239 | + config_file.write(' args: ["☃"]\n') |
| 240 | + local['git']('add', '.pre-commit-config.yaml') |
| 241 | + stage_a_file() |
| 242 | + |
| 243 | + install(Runner(repo_with_failing_hook)) |
| 244 | + |
| 245 | + # Don't want to write to home directory |
| 246 | + env = dict(os.environ, **{'PRE_COMMIT_HOME': tmpdir_factory.get()}) |
| 247 | + # Have to use subprocess because pytest monkeypatches sys.stdout |
| 248 | + _, stdout, _ = local['git'].run( |
| 249 | + ('commit', '-m', 'Commit!'), |
| 250 | + # git commit puts pre-commit to stderr |
| 251 | + stderr=subprocess.STDOUT, |
| 252 | + env=env, |
| 253 | + retcode=None, |
| 254 | + ) |
| 255 | + assert 'UnicodeEncodeError' not in stdout |
| 256 | + # Doesn't actually happen, but a reasonable assertion |
| 257 | + assert 'UnicodeDecodeError' not in stdout |
0 commit comments