|
| 1 | +# -*- coding: utf-8 -*- |
1 | 2 | from __future__ import absolute_import |
2 | 3 | from __future__ import unicode_literals |
3 | 4 |
|
4 | | -from unittest import mock |
5 | | - |
6 | 5 | import pytest |
7 | 6 |
|
8 | 7 | from pre_commit import xargs |
9 | 8 |
|
10 | 9 |
|
11 | 10 | @pytest.fixture |
12 | | -def sys_win32_mock(): |
13 | | - return mock.Mock( |
| 11 | +def sys_win32_mock(mocker): |
| 12 | + return mocker.Mock( |
14 | 13 | platform='win32', |
15 | | - getdefaultencoding=mock.Mock(return_value='utf-8'), |
| 14 | + getdefaultencoding=mocker.Mock(return_value='utf-8'), |
16 | 15 | ) |
17 | 16 |
|
18 | 17 |
|
19 | 18 | @pytest.fixture |
20 | | -def sys_linux_mock(): |
21 | | - return mock.Mock( |
| 19 | +def sys_linux_mock(mocker): |
| 20 | + return mocker.Mock( |
22 | 21 | platform='linux', |
23 | | - getdefaultencoding=mock.Mock(return_value='utf-8'), |
| 22 | + getdefaultencoding=mocker.Mock(return_value='utf-8'), |
24 | 23 | ) |
25 | 24 |
|
26 | 25 |
|
@@ -53,28 +52,28 @@ def test_partition_limits(): |
53 | 52 | ) |
54 | 53 |
|
55 | 54 |
|
56 | | -def test_partition_limit_win32(sys_win32_mock): |
| 55 | +def test_partition_limit_win32(mocker, sys_win32_mock): |
57 | 56 | cmd = ('ninechars',) |
58 | 57 | 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): |
60 | 59 | ret = xargs.partition(cmd, varargs, _max_length=20) |
61 | 60 |
|
62 | 61 | assert ret == (cmd + varargs,) |
63 | 62 |
|
64 | 63 |
|
65 | | -def test_partition_limit_linux(sys_linux_mock): |
| 64 | +def test_partition_limit_linux(mocker, sys_linux_mock): |
66 | 65 | cmd = ('ninechars',) |
67 | 66 | 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): |
69 | 68 | ret = xargs.partition(cmd, varargs, _max_length=30) |
70 | 69 |
|
71 | 70 | assert ret == (cmd + varargs,) |
72 | 71 |
|
73 | 72 |
|
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): |
75 | 74 | cmd = ('ninechars',) |
76 | 75 | 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): |
78 | 77 | with pytest.raises(xargs.ArgumentTooLongError): |
79 | 78 | xargs.partition(cmd, varargs, _max_length=20) |
80 | 79 |
|
|
0 commit comments