mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix Py3
This commit is contained in:
parent
5eda121260
commit
cd36e9e779
3 changed files with 12 additions and 5 deletions
|
|
@ -2,6 +2,8 @@ import os
|
||||||
import os.path
|
import os.path
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from pre_commit import five
|
||||||
|
|
||||||
|
|
||||||
class CalledProcessError(RuntimeError):
|
class CalledProcessError(RuntimeError):
|
||||||
def __init__(self, returncode, cmd, expected_returncode, output=None):
|
def __init__(self, returncode, cmd, expected_returncode, output=None):
|
||||||
|
|
@ -63,6 +65,11 @@ class PrefixedCommandRunner(object):
|
||||||
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
|
replaced_cmd = _replace_cmd(cmd, prefix=self.prefix_dir)
|
||||||
proc = self.__popen(replaced_cmd, **popen_kwargs)
|
proc = self.__popen(replaced_cmd, **popen_kwargs)
|
||||||
stdout, stderr = proc.communicate(stdin)
|
stdout, stderr = proc.communicate(stdin)
|
||||||
|
# TODO: stdout, stderr = from_bytes(stdout), from_bytes(stderr)
|
||||||
|
if stdout is not None and not isinstance(stdout, five.text):
|
||||||
|
stdout = five.text(stdout, 'utf-8')
|
||||||
|
if stderr is not None and not isinstance(stderr, five.text):
|
||||||
|
stderr = five.text(stderr, 'utf-8')
|
||||||
returncode = proc.returncode
|
returncode = proc.returncode
|
||||||
|
|
||||||
if retcode is not None and retcode != returncode:
|
if retcode is not None and retcode != returncode:
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ def test_CalledProcessError_str():
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def popen_mock():
|
def popen_mock():
|
||||||
popen = mock.Mock(spec=subprocess.Popen)
|
popen = mock.Mock(spec=subprocess.Popen)
|
||||||
popen.return_value.communicate.return_value = (mock.Mock(), mock.Mock())
|
popen.return_value.communicate.return_value = ('stdout', 'stderr')
|
||||||
return popen
|
return popen
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ def test_run_a_python_hook(config_for_python_hooks_repo):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert ret[1] == b"['/dev/null']\nHello World\n"
|
assert ret[1] == "['/dev/null']\nHello World\n"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|
@ -77,7 +77,7 @@ def test_cwd_of_hook(config_for_prints_cwd_repo):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert ret[1] == repo.repo_url.encode('utf-8') + b'\n'
|
assert ret[1] == repo.repo_url + '\n'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skipif(
|
@pytest.mark.skipif(
|
||||||
|
|
@ -90,7 +90,7 @@ def test_run_a_node_hook(config_for_node_hooks_repo):
|
||||||
ret = repo.run_hook(PrefixedCommandRunner(C.HOOKS_WORKSPACE), 'foo', [])
|
ret = repo.run_hook(PrefixedCommandRunner(C.HOOKS_WORKSPACE), 'foo', [])
|
||||||
|
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert ret[1] == b'Hello World\n'
|
assert ret[1] == 'Hello World\n'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
|
|
@ -101,7 +101,7 @@ def test_run_a_script_hook(config_for_script_hooks_repo):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert ret[0] == 0
|
assert ret[0] == 0
|
||||||
assert ret[1] == b'bar\nHello World\n'
|
assert ret[1] == 'bar\nHello World\n'
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue