mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-24 16:08:31 -05:00
Merge pull request #839 from georgeyk/refactor-xargs-partition
Update xargs.partition with platform information
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit import xargs
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def win32_py2_mock():
|
||||
with mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8'):
|
||||
with mock.patch.object(sys, 'platform', 'win32'):
|
||||
with mock.patch.object(six, 'PY2', True):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def win32_py3_mock():
|
||||
with mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8'):
|
||||
with mock.patch.object(sys, 'platform', 'win32'):
|
||||
with mock.patch.object(six, 'PY2', False):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def linux_mock():
|
||||
with mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8'):
|
||||
with mock.patch.object(sys, 'platform', 'linux'):
|
||||
yield
|
||||
|
||||
|
||||
def test_partition_trivial():
|
||||
assert xargs.partition(('cmd',), ()) == (('cmd',),)
|
||||
|
||||
@@ -35,6 +63,35 @@ def test_partition_limits():
|
||||
)
|
||||
|
||||
|
||||
def test_partition_limit_win32_py3(win32_py3_mock):
|
||||
cmd = ('ninechars',)
|
||||
# counted as half because of utf-16 encode
|
||||
varargs = ('😑' * 5,)
|
||||
ret = xargs.partition(cmd, varargs, _max_length=20)
|
||||
assert ret == (cmd + varargs,)
|
||||
|
||||
|
||||
def test_partition_limit_win32_py2(win32_py2_mock):
|
||||
cmd = ('ninechars',)
|
||||
varargs = ('😑' * 5,) # 4 bytes * 5
|
||||
ret = xargs.partition(cmd, varargs, _max_length=30)
|
||||
assert ret == (cmd + varargs,)
|
||||
|
||||
|
||||
def test_partition_limit_linux(linux_mock):
|
||||
cmd = ('ninechars',)
|
||||
varargs = ('😑' * 5,)
|
||||
ret = xargs.partition(cmd, varargs, _max_length=30)
|
||||
assert ret == (cmd + varargs,)
|
||||
|
||||
|
||||
def test_argument_too_long_with_large_unicode(linux_mock):
|
||||
cmd = ('ninechars',)
|
||||
varargs = ('😑' * 10,) # 4 bytes * 10
|
||||
with pytest.raises(xargs.ArgumentTooLongError):
|
||||
xargs.partition(cmd, varargs, _max_length=20)
|
||||
|
||||
|
||||
def test_argument_too_long():
|
||||
with pytest.raises(xargs.ArgumentTooLongError):
|
||||
xargs.partition(('a' * 5,), ('a' * 5,), _max_length=10)
|
||||
|
||||
Reference in New Issue
Block a user