Skip to content

Commit df5d171

Browse files
committed
Fix xargs.partition tests in python2.7 (pytest-mock)
1 parent fa4c03d commit df5d171

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ flake8
55
mock
66
pytest
77
pytest-env
8+
pytest-mock

tests/xargs_test.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1+
# -*- coding: utf-8 -*-
12
from __future__ import absolute_import
23
from __future__ import unicode_literals
34

4-
from unittest import mock
5-
65
import pytest
76

87
from pre_commit import xargs
98

109

1110
@pytest.fixture
12-
def sys_win32_mock():
13-
return mock.Mock(
11+
def sys_win32_mock(mocker):
12+
return mocker.Mock(
1413
platform='win32',
15-
getdefaultencoding=mock.Mock(return_value='utf-8'),
14+
getdefaultencoding=mocker.Mock(return_value='utf-8'),
1615
)
1716

1817

1918
@pytest.fixture
20-
def sys_linux_mock():
21-
return mock.Mock(
19+
def sys_linux_mock(mocker):
20+
return mocker.Mock(
2221
platform='linux',
23-
getdefaultencoding=mock.Mock(return_value='utf-8'),
22+
getdefaultencoding=mocker.Mock(return_value='utf-8'),
2423
)
2524

2625

@@ -53,28 +52,28 @@ def test_partition_limits():
5352
)
5453

5554

56-
def test_partition_limit_win32(sys_win32_mock):
55+
def test_partition_limit_win32(mocker, sys_win32_mock):
5756
cmd = ('ninechars',)
5857
varargs = ('😑' * 10,)
59-
with mock.patch('pre_commit.xargs.sys', sys_win32_mock):
58+
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_win32_mock):
6059
ret = xargs.partition(cmd, varargs, _max_length=20)
6160

6261
assert ret == (cmd + varargs,)
6362

6463

65-
def test_partition_limit_linux(sys_linux_mock):
64+
def test_partition_limit_linux(mocker, sys_linux_mock):
6665
cmd = ('ninechars',)
6766
varargs = ('😑' * 5,)
68-
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
67+
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_linux_mock):
6968
ret = xargs.partition(cmd, varargs, _max_length=30)
7069

7170
assert ret == (cmd + varargs,)
7271

7372

74-
def test_argument_too_long_with_large_unicode(sys_linux_mock):
73+
def test_argument_too_long_with_large_unicode(mocker, sys_linux_mock):
7574
cmd = ('ninechars',)
7675
varargs = ('😑' * 10,) # 4 bytes * 10
77-
with mock.patch('pre_commit.xargs.sys', sys_linux_mock):
76+
with mocker.mock_module.patch('pre_commit.xargs.sys', sys_linux_mock):
7877
with pytest.raises(xargs.ArgumentTooLongError):
7978
xargs.partition(cmd, varargs, _max_length=20)
8079

0 commit comments

Comments
 (0)