mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix xargs.partition tests in python2.7 (pytest-mock)
This commit is contained in:
parent
fa4c03da65
commit
df5d171cd7
2 changed files with 14 additions and 14 deletions
|
|
@ -5,3 +5,4 @@ flake8
|
||||||
mock
|
mock
|
||||||
pytest
|
pytest
|
||||||
pytest-env
|
pytest-env
|
||||||
|
pytest-mock
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,25 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import mock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from pre_commit import xargs
|
from pre_commit import xargs
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sys_win32_mock():
|
def sys_win32_mock(mocker):
|
||||||
return mock.Mock(
|
return mocker.Mock(
|
||||||
platform='win32',
|
platform='win32',
|
||||||
getdefaultencoding=mock.Mock(return_value='utf-8'),
|
getdefaultencoding=mocker.Mock(return_value='utf-8'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def sys_linux_mock():
|
def sys_linux_mock(mocker):
|
||||||
return mock.Mock(
|
return mocker.Mock(
|
||||||
platform='linux',
|
platform='linux',
|
||||||
getdefaultencoding=mock.Mock(return_value='utf-8'),
|
getdefaultencoding=mocker.Mock(return_value='utf-8'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -53,28 +52,28 @@ def test_partition_limits():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_partition_limit_win32(sys_win32_mock):
|
def test_partition_limit_win32(mocker, sys_win32_mock):
|
||||||
cmd = ('ninechars',)
|
cmd = ('ninechars',)
|
||||||
varargs = ('😑' * 10,)
|
varargs = ('😑' * 10,)
|
||||||
with mock.patch('pre_commit.xargs.sys', sys_win32_mock):
|
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_win32_mock):
|
||||||
ret = xargs.partition(cmd, varargs, _max_length=20)
|
ret = xargs.partition(cmd, varargs, _max_length=20)
|
||||||
|
|
||||||
assert ret == (cmd + varargs,)
|
assert ret == (cmd + varargs,)
|
||||||
|
|
||||||
|
|
||||||
def test_partition_limit_linux(sys_linux_mock):
|
def test_partition_limit_linux(mocker, sys_linux_mock):
|
||||||
cmd = ('ninechars',)
|
cmd = ('ninechars',)
|
||||||
varargs = ('😑' * 5,)
|
varargs = ('😑' * 5,)
|
||||||
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
|
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_linux_mock):
|
||||||
ret = xargs.partition(cmd, varargs, _max_length=30)
|
ret = xargs.partition(cmd, varargs, _max_length=30)
|
||||||
|
|
||||||
assert ret == (cmd + varargs,)
|
assert ret == (cmd + varargs,)
|
||||||
|
|
||||||
|
|
||||||
def test_argument_too_long_with_large_unicode(sys_linux_mock):
|
def test_argument_too_long_with_large_unicode(mocker, sys_linux_mock):
|
||||||
cmd = ('ninechars',)
|
cmd = ('ninechars',)
|
||||||
varargs = ('😑' * 10,) # 4 bytes * 10
|
varargs = ('😑' * 10,) # 4 bytes * 10
|
||||||
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
|
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_linux_mock):
|
||||||
with pytest.raises(xargs.ArgumentTooLongError):
|
with pytest.raises(xargs.ArgumentTooLongError):
|
||||||
xargs.partition(cmd, varargs, _max_length=20)
|
xargs.partition(cmd, varargs, _max_length=20)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue