From df5d171cd7709db434f93474591aa867a69abe81 Mon Sep 17 00:00:00 2001 From: "George Y. Kussumoto" Date: Fri, 5 Oct 2018 14:33:32 -0300 Subject: [PATCH] Fix xargs.partition tests in python2.7 (pytest-mock) --- requirements-dev.txt | 1 + tests/xargs_test.py | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 157f287d..bd7f8411 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -5,3 +5,4 @@ flake8 mock pytest pytest-env +pytest-mock diff --git a/tests/xargs_test.py b/tests/xargs_test.py index 84d4899b..e68f46c5 100644 --- a/tests/xargs_test.py +++ b/tests/xargs_test.py @@ -1,26 +1,25 @@ +# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import unicode_literals -from unittest import mock - import pytest from pre_commit import xargs @pytest.fixture -def sys_win32_mock(): - return mock.Mock( +def sys_win32_mock(mocker): + return mocker.Mock( platform='win32', - getdefaultencoding=mock.Mock(return_value='utf-8'), + getdefaultencoding=mocker.Mock(return_value='utf-8'), ) @pytest.fixture -def sys_linux_mock(): - return mock.Mock( +def sys_linux_mock(mocker): + return mocker.Mock( 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',) 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) assert ret == (cmd + varargs,) -def test_partition_limit_linux(sys_linux_mock): +def test_partition_limit_linux(mocker, sys_linux_mock): cmd = ('ninechars',) 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) 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',) 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): xargs.partition(cmd, varargs, _max_length=20)