mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Python 3 compatibility.
This commit is contained in:
parent
ddebb83a40
commit
bb365a6e68
10 changed files with 30 additions and 27 deletions
|
|
@ -1,17 +1,9 @@
|
|||
import __builtin__
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from pre_commit import color
|
||||
from pre_commit.logging_handler import LoggingHandler
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def print_mock():
|
||||
with mock.patch.object(__builtin__, 'print', autospec=True) as print_mock:
|
||||
yield print_mock
|
||||
|
||||
|
||||
class FakeLogRecord(object):
|
||||
def __init__(self, message, levelname, levelno):
|
||||
self.message = message
|
||||
|
|
@ -22,16 +14,18 @@ class FakeLogRecord(object):
|
|||
return self.message
|
||||
|
||||
|
||||
def test_logging_handler_color(print_mock):
|
||||
handler = LoggingHandler(True)
|
||||
def test_logging_handler_color():
|
||||
print_mock = mock.Mock()
|
||||
handler = LoggingHandler(True, print_mock)
|
||||
handler.emit(FakeLogRecord('hi', 'WARNING', 30))
|
||||
print_mock.assert_called_once_with(
|
||||
color.YELLOW + '[WARNING]' + color.NORMAL + ' hi',
|
||||
)
|
||||
|
||||
|
||||
def test_logging_handler_no_color(print_mock):
|
||||
handler = LoggingHandler(False)
|
||||
def test_logging_handler_no_color():
|
||||
print_mock = mock.Mock()
|
||||
handler = LoggingHandler(False, print_mock)
|
||||
handler.emit(FakeLogRecord('hi', 'WARNING', 30))
|
||||
print_mock.assert_called_once_with(
|
||||
'[WARNING] hi',
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ def test_run_a_python_hook(config_for_python_hooks_repo):
|
|||
)
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == "['/dev/null']\nHello World\n"
|
||||
assert ret[1] == b"['/dev/null']\nHello World\n"
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
|
@ -77,7 +77,7 @@ def test_cwd_of_hook(config_for_prints_cwd_repo):
|
|||
)
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == '{0}\n'.format(repo.repo_url)
|
||||
assert ret[1] == repo.repo_url.encode('utf-8') + b'\n'
|
||||
|
||||
|
||||
@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', [])
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'Hello World\n'
|
||||
assert ret[1] == b'Hello World\n'
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
|
|
@ -101,7 +101,7 @@ def test_run_a_script_hook(config_for_script_hooks_repo):
|
|||
)
|
||||
|
||||
assert ret[0] == 0
|
||||
assert ret[1] == 'bar\nHello World\n'
|
||||
assert ret[1] == b'bar\nHello World\n'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
|
|||
|
|
@ -118,8 +118,8 @@ def img_staged(empty_git_dir):
|
|||
def _test_img_state(path, expected_file='img1.jpg', status='A'):
|
||||
assert os.path.exists(path.img_filename)
|
||||
assert (
|
||||
open(path.img_filename).read() ==
|
||||
open(get_resource_path(expected_file)).read()
|
||||
open(path.img_filename, 'rb').read() ==
|
||||
open(get_resource_path(expected_file), 'rb').read()
|
||||
)
|
||||
actual_status = get_short_git_status()['img.jpg']
|
||||
assert status == actual_status
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue