some manual py2 cleanups

This commit is contained in:
Anthony Sottile 2020-01-08 21:23:18 -08:00
parent 30c1e8289f
commit ab19b94811
23 changed files with 31 additions and 59 deletions

View file

@ -1,6 +1,6 @@
import sys
from unittest import mock
import mock
import pytest
from pre_commit import envcontext

View file

@ -1,6 +1,6 @@
import os.path
from unittest import mock
import mock
import pytest
from pre_commit.commands.clean import clean

View file

@ -1,6 +1,5 @@
import os.path
import mock
from unittest import mock
import pre_commit.constants as C
from pre_commit.commands.init_templatedir import init_templatedir

View file

@ -1,8 +1,7 @@
import os.path
import re
import sys
import mock
from unittest import mock
import pre_commit.constants as C
from pre_commit.commands.install_uninstall import CURRENT_HASH

View file

@ -2,8 +2,8 @@ import os.path
import pipes
import sys
import time
from unittest import mock
import mock
import pytest
import pre_commit.constants as C

View file

@ -1,8 +1,7 @@
import os.path
import re
import time
import mock
from unittest import mock
from pre_commit import git
from pre_commit.commands.try_repo import try_repo

View file

@ -2,8 +2,8 @@ import functools
import io
import logging
import os.path
from unittest import mock
import mock
import pytest
from pre_commit import output

View file

@ -1,6 +1,6 @@
import os
from unittest import mock
import mock
import pytest
from pre_commit.envcontext import envcontext
@ -91,11 +91,11 @@ def test_exception_safety():
class MyError(RuntimeError):
pass
env = {}
env = {'hello': 'world'}
with pytest.raises(MyError):
with envcontext([('foo', 'bar')], _env=env):
raise MyError()
assert env == {}
assert env == {'hello': 'world'}
def test_integration_os_environ():

View file

@ -1,8 +1,8 @@
import os.path
import re
import sys
from unittest import mock
import mock
import pytest
from pre_commit import error_handler

View file

@ -11,7 +11,6 @@ ArgSpec = functools.partial(
inspect.FullArgSpec, varargs=None, varkw=None, defaults=None,
kwonlyargs=[], kwonlydefaults=None, annotations={},
)
getargspec = inspect.getfullargspec
@pytest.mark.parametrize('language', all_languages)
@ -19,7 +18,7 @@ def test_install_environment_argspec(language):
expected_argspec = ArgSpec(
args=['prefix', 'version', 'additional_dependencies'],
)
argspec = getargspec(languages[language].install_environment)
argspec = inspect.getfullargpsec(languages[language].install_environment)
assert argspec == expected_argspec
@ -31,19 +30,19 @@ def test_ENVIRONMENT_DIR(language):
@pytest.mark.parametrize('language', all_languages)
def test_run_hook_argpsec(language):
expected_argspec = ArgSpec(args=['hook', 'file_args', 'color'])
argspec = getargspec(languages[language].run_hook)
argspec = inspect.getfullargpsec(languages[language].run_hook)
assert argspec == expected_argspec
@pytest.mark.parametrize('language', all_languages)
def test_get_default_version_argspec(language):
expected_argspec = ArgSpec(args=[])
argspec = getargspec(languages[language].get_default_version)
argspec = inspect.getfullargpsec(languages[language].get_default_version)
assert argspec == expected_argspec
@pytest.mark.parametrize('language', all_languages)
def test_healthy_argspec(language):
expected_argspec = ArgSpec(args=['prefix', 'language_version'])
argspec = getargspec(languages[language].healthy)
argspec = inspect.getfullargpsec(languages[language].healthy)
assert argspec == expected_argspec

View file

@ -1,4 +1,4 @@
import mock
from unittest import mock
from pre_commit.languages import docker
from pre_commit.util import CalledProcessError

View file

@ -1,8 +1,8 @@
import multiprocessing
import os
import sys
from unittest import mock
import mock
import pytest
import pre_commit.constants as C

View file

@ -1,7 +1,7 @@
import os.path
import sys
from unittest import mock
import mock
import pytest
import pre_commit.constants as C

View file

@ -1,7 +1,7 @@
import argparse
import os.path
from unittest import mock
import mock
import pytest
import pre_commit.constants as C

View file

@ -1,4 +1,5 @@
import mock
from unittest import mock
import pytest
from pre_commit import color

View file

@ -2,9 +2,9 @@ import os.path
import re
import shutil
import sys
from unittest import mock
import cfgv
import mock
import pytest
import pre_commit.constants as C

View file

@ -1,7 +1,7 @@
import os.path
import sqlite3
from unittest import mock
import mock
import pytest
from pre_commit import git

View file

@ -2,10 +2,9 @@ import concurrent.futures
import os
import sys
import time
from unittest import mock
import mock
import pytest
import six
from pre_commit import parse_shebang
from pre_commit import xargs
@ -26,19 +25,10 @@ def test_environ_size(env, expected):
@pytest.fixture
def win32_py2_mock():
def win32_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
yield
@pytest.fixture
@ -78,7 +68,7 @@ def test_partition_limits():
)
def test_partition_limit_win32_py3(win32_py3_mock):
def test_partition_limit_win32(win32_mock):
cmd = ('ninechars',)
# counted as half because of utf-16 encode
varargs = ('😑' * 5,)
@ -86,13 +76,6 @@ def test_partition_limit_win32_py3(win32_py3_mock):
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, 1, _max_length=31)
assert ret == (cmd + varargs,)
def test_partition_limit_linux(linux_mock):
cmd = ('ninechars',)
varargs = ('😑' * 5,)