mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 01:51:46 +04:00
upgrade hooks, pyupgrade pre-commit
This commit is contained in:
parent
764c765d29
commit
30c1e8289f
91 changed files with 176 additions and 437 deletions
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
|
||||
import cfgv
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import sys
|
||||
|
||||
import mock
|
||||
|
|
@ -14,7 +12,7 @@ from pre_commit.color import use_color
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
('in_text', 'in_color', 'in_use_color', 'expected'), (
|
||||
('foo', GREEN, True, '{}foo\033[0m'.format(GREEN)),
|
||||
('foo', GREEN, True, f'{GREEN}foo\033[0m'),
|
||||
('foo', GREEN, False, 'foo'),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pipes
|
||||
|
||||
import pytest
|
||||
|
|
@ -213,7 +211,7 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name(
|
|||
|
||||
with open(C.CONFIG_FILE) as f:
|
||||
before = f.read()
|
||||
repo_name = 'file://{}'.format(out_of_date.path)
|
||||
repo_name = f'file://{out_of_date.path}'
|
||||
ret = autoupdate(
|
||||
C.CONFIG_FILE, store, freeze=False, tags_only=False,
|
||||
repos=(repo_name,),
|
||||
|
|
@ -312,7 +310,7 @@ def test_autoupdate_freeze(tagged, in_tmpdir, store):
|
|||
|
||||
assert autoupdate(C.CONFIG_FILE, store, freeze=True, tags_only=False) == 0
|
||||
with open(C.CONFIG_FILE) as f:
|
||||
expected = 'rev: {} # frozen: v1.2.3'.format(tagged.head_rev)
|
||||
expected = f'rev: {tagged.head_rev} # frozen: v1.2.3'
|
||||
assert expected in f.read()
|
||||
|
||||
# if we un-freeze it should remove the frozen comment
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import mock
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -123,7 +118,7 @@ def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
|
|||
fn=cmd_output_mocked_pre_commit_home,
|
||||
retcode=None,
|
||||
tempdir_factory=tempdir_factory,
|
||||
**kwargs
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -203,7 +198,7 @@ def test_commit_am(tempdir_factory, store):
|
|||
open('unstaged', 'w').close()
|
||||
cmd_output('git', 'add', '.')
|
||||
git_commit(cwd=path)
|
||||
with io.open('unstaged', 'w') as foo_file:
|
||||
with open('unstaged', 'w') as foo_file:
|
||||
foo_file.write('Oh hai')
|
||||
|
||||
assert install(C.CONFIG_FILE, store, hook_types=['pre-commit']) == 0
|
||||
|
|
@ -314,7 +309,7 @@ EXISTING_COMMIT_RUN = re.compile(
|
|||
|
||||
def _write_legacy_hook(path):
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write('#!/usr/bin/env bash\necho "legacy hook"\n')
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -377,7 +372,7 @@ def test_failing_existing_hook_returns_1(tempdir_factory, store):
|
|||
with cwd(path):
|
||||
# Write out a failing "old" hook
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write('#!/usr/bin/env bash\necho "fail!"\nexit 1\n')
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -439,7 +434,7 @@ def test_replace_old_commit_script(tempdir_factory, store):
|
|||
)
|
||||
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
|
||||
f.write(new_contents)
|
||||
make_executable(f.name)
|
||||
|
||||
|
|
@ -525,7 +520,7 @@ def _get_push_output(tempdir_factory, opts=()):
|
|||
return cmd_output_mocked_pre_commit_home(
|
||||
'git', 'push', 'origin', 'HEAD:new_branch', *opts,
|
||||
tempdir_factory=tempdir_factory,
|
||||
retcode=None
|
||||
retcode=None,
|
||||
)[:2]
|
||||
|
||||
|
||||
|
|
@ -616,7 +611,7 @@ def test_pre_push_legacy(tempdir_factory, store):
|
|||
cmd_output('git', 'clone', upstream, path)
|
||||
with cwd(path):
|
||||
mkdirp(os.path.join(path, '.git/hooks'))
|
||||
with io.open(os.path.join(path, '.git/hooks/pre-push'), 'w') as f:
|
||||
with open(os.path.join(path, '.git/hooks/pre-push'), 'w') as f:
|
||||
f.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -665,7 +660,7 @@ def test_commit_msg_integration_passing(
|
|||
def test_commit_msg_legacy(commit_msg_repo, tempdir_factory, store):
|
||||
hook_path = os.path.join(commit_msg_repo, '.git/hooks/commit-msg')
|
||||
mkdirp(os.path.dirname(hook_path))
|
||||
with io.open(hook_path, 'w') as hook_file:
|
||||
with open(hook_path, 'w') as hook_file:
|
||||
hook_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -709,7 +704,7 @@ def test_prepare_commit_msg_integration_passing(
|
|||
commit_msg_path = os.path.join(
|
||||
prepare_commit_msg_repo, '.git/COMMIT_EDITMSG',
|
||||
)
|
||||
with io.open(commit_msg_path) as f:
|
||||
with open(commit_msg_path) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
@ -720,7 +715,7 @@ def test_prepare_commit_msg_legacy(
|
|||
prepare_commit_msg_repo, '.git/hooks/prepare-commit-msg',
|
||||
)
|
||||
mkdirp(os.path.dirname(hook_path))
|
||||
with io.open(hook_path, 'w') as hook_file:
|
||||
with open(hook_path, 'w') as hook_file:
|
||||
hook_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -739,7 +734,7 @@ def test_prepare_commit_msg_legacy(
|
|||
commit_msg_path = os.path.join(
|
||||
prepare_commit_msg_repo, '.git/COMMIT_EDITMSG',
|
||||
)
|
||||
with io.open(commit_msg_path) as f:
|
||||
with open(commit_msg_path) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
import pre_commit.constants as C
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import pipes
|
||||
import sys
|
||||
|
|
@ -154,7 +150,7 @@ def test_types_hook_repository(cap_out, store, tempdir_factory):
|
|||
def test_exclude_types_hook_repository(cap_out, store, tempdir_factory):
|
||||
git_path = make_consuming_repo(tempdir_factory, 'exclude_types_repo')
|
||||
with cwd(git_path):
|
||||
with io.open('exe', 'w') as exe:
|
||||
with open('exe', 'w') as exe:
|
||||
exe.write('#!/usr/bin/env python3\n')
|
||||
make_executable('exe')
|
||||
cmd_output('git', 'add', 'exe')
|
||||
|
|
@ -601,8 +597,8 @@ def test_stages(cap_out, store, repo_with_passing_hook):
|
|||
'repo': 'local',
|
||||
'hooks': [
|
||||
{
|
||||
'id': 'do-not-commit-{}'.format(i),
|
||||
'name': 'hook {}'.format(i),
|
||||
'id': f'do-not-commit-{i}',
|
||||
'name': f'hook {i}',
|
||||
'entry': 'DO NOT COMMIT',
|
||||
'language': 'pygrep',
|
||||
'stages': [stage],
|
||||
|
|
@ -636,7 +632,7 @@ def test_stages(cap_out, store, repo_with_passing_hook):
|
|||
|
||||
def test_commit_msg_hook(cap_out, store, commit_msg_repo):
|
||||
filename = '.git/COMMIT_EDITMSG'
|
||||
with io.open(filename, 'w') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write('This is the commit message')
|
||||
|
||||
_test_run(
|
||||
|
|
@ -652,7 +648,7 @@ def test_commit_msg_hook(cap_out, store, commit_msg_repo):
|
|||
|
||||
def test_prepare_commit_msg_hook(cap_out, store, prepare_commit_msg_repo):
|
||||
filename = '.git/COMMIT_EDITMSG'
|
||||
with io.open(filename, 'w') as f:
|
||||
with open(filename, 'w') as f:
|
||||
f.write('This is the commit message')
|
||||
|
||||
_test_run(
|
||||
|
|
@ -665,7 +661,7 @@ def test_prepare_commit_msg_hook(cap_out, store, prepare_commit_msg_repo):
|
|||
stage=False,
|
||||
)
|
||||
|
||||
with io.open(filename) as f:
|
||||
with open(filename) as f:
|
||||
assert 'Signed off by: ' in f.read()
|
||||
|
||||
|
||||
|
|
@ -692,7 +688,7 @@ def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
|
|||
}
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
with io.open('dummy.py', 'w') as staged_file:
|
||||
with open('dummy.py', 'w') as staged_file:
|
||||
staged_file.write('"""TODO: something"""\n')
|
||||
cmd_output('git', 'add', 'dummy.py')
|
||||
|
||||
|
|
@ -719,7 +715,7 @@ def test_local_hook_fails(cap_out, store, repo_with_passing_hook):
|
|||
}
|
||||
add_config_to_repo(repo_with_passing_hook, config)
|
||||
|
||||
with io.open('dummy.py', 'w') as staged_file:
|
||||
with open('dummy.py', 'w') as staged_file:
|
||||
staged_file.write('"""TODO: something"""\n')
|
||||
cmd_output('git', 'add', 'dummy.py')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit.commands.sample_config import sample_config
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import time
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import io
|
||||
import logging
|
||||
|
|
@ -8,7 +5,6 @@ import os.path
|
|||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit import output
|
||||
from pre_commit.envcontext import envcontext
|
||||
|
|
@ -36,19 +32,19 @@ def no_warnings(recwarn):
|
|||
' missing __init__' in message
|
||||
):
|
||||
warnings.append(
|
||||
'{}:{} {}'.format(warning.filename, warning.lineno, message),
|
||||
f'{warning.filename}:{warning.lineno} {message}',
|
||||
)
|
||||
assert not warnings
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tempdir_factory(tmpdir):
|
||||
class TmpdirFactory(object):
|
||||
class TmpdirFactory:
|
||||
def __init__(self):
|
||||
self.tmpdir_count = 0
|
||||
|
||||
def get(self):
|
||||
path = tmpdir.join(six.text_type(self.tmpdir_count)).strpath
|
||||
path = tmpdir.join(str(self.tmpdir_count)).strpath
|
||||
self.tmpdir_count += 1
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
|
@ -73,18 +69,18 @@ def in_git_dir(tmpdir):
|
|||
|
||||
def _make_conflict():
|
||||
cmd_output('git', 'checkout', 'origin/master', '-b', 'foo')
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('herp\nderp\n')
|
||||
cmd_output('git', 'add', 'conflict_file')
|
||||
with io.open('foo_only_file', 'w') as foo_only_file:
|
||||
with open('foo_only_file', 'w') as foo_only_file:
|
||||
foo_only_file.write('foo')
|
||||
cmd_output('git', 'add', 'foo_only_file')
|
||||
git_commit(msg=_make_conflict.__name__)
|
||||
cmd_output('git', 'checkout', 'origin/master', '-b', 'bar')
|
||||
with io.open('conflict_file', 'w') as conflict_file:
|
||||
with open('conflict_file', 'w') as conflict_file:
|
||||
conflict_file.write('harp\nddrp\n')
|
||||
cmd_output('git', 'add', 'conflict_file')
|
||||
with io.open('bar_only_file', 'w') as bar_only_file:
|
||||
with open('bar_only_file', 'w') as bar_only_file:
|
||||
bar_only_file.write('bar')
|
||||
cmd_output('git', 'add', 'bar_only_file')
|
||||
git_commit(msg=_make_conflict.__name__)
|
||||
|
|
@ -145,14 +141,14 @@ def prepare_commit_msg_repo(tempdir_factory):
|
|||
'hooks': [{
|
||||
'id': 'add-signoff',
|
||||
'name': 'Add "Signed off by:"',
|
||||
'entry': './{}'.format(script_name),
|
||||
'entry': f'./{script_name}',
|
||||
'language': 'script',
|
||||
'stages': ['prepare-commit-msg'],
|
||||
}],
|
||||
}
|
||||
write_config(path, config)
|
||||
with cwd(path):
|
||||
with io.open(script_name, 'w') as script_file:
|
||||
with open(script_name, 'w') as script_file:
|
||||
script_file.write(
|
||||
'#!/usr/bin/env bash\n'
|
||||
'set -eu\n'
|
||||
|
|
@ -229,7 +225,7 @@ def log_info_mock():
|
|||
yield mck
|
||||
|
||||
|
||||
class FakeStream(object):
|
||||
class FakeStream:
|
||||
def __init__(self):
|
||||
self.data = io.BytesIO()
|
||||
|
||||
|
|
@ -240,7 +236,7 @@ class FakeStream(object):
|
|||
pass
|
||||
|
||||
|
||||
class Fixture(object):
|
||||
class Fixture:
|
||||
def __init__(self, stream):
|
||||
self._stream = stream
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import mock
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
|
@ -109,7 +104,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
|
|||
)
|
||||
|
||||
assert os.path.exists(log_file)
|
||||
with io.open(log_file) as f:
|
||||
with open(log_file) as f:
|
||||
logged = f.read()
|
||||
expected = (
|
||||
r'^### version information\n'
|
||||
|
|
@ -158,4 +153,4 @@ def test_error_handler_no_tty(tempdir_factory):
|
|||
log_file = os.path.join(pre_commit_home, 'pre-commit.log')
|
||||
out_lines = out.splitlines()
|
||||
assert out_lines[-2] == 'An unexpected error has occurred: ValueError: ☃'
|
||||
assert out_lines[-1] == 'Check the log at {}'.format(log_file)
|
||||
assert out_lines[-1] == f'Check the log at {log_file}'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,26 +1,17 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import functools
|
||||
import inspect
|
||||
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit.languages.all import all_languages
|
||||
from pre_commit.languages.all import languages
|
||||
|
||||
|
||||
if six.PY2: # pragma: no cover
|
||||
ArgSpec = functools.partial(
|
||||
inspect.ArgSpec, varargs=None, keywords=None, defaults=None,
|
||||
)
|
||||
getargspec = inspect.getargspec
|
||||
else: # pragma: no cover
|
||||
ArgSpec = functools.partial(
|
||||
inspect.FullArgSpec, varargs=None, varkw=None, defaults=None,
|
||||
kwonlyargs=[], kwonlydefaults=None, annotations={},
|
||||
)
|
||||
getargspec = inspect.getfullargspec
|
||||
ArgSpec = functools.partial(
|
||||
inspect.FullArgSpec, varargs=None, varkw=None, defaults=None,
|
||||
kwonlyargs=[], kwonlydefaults=None, annotations={},
|
||||
)
|
||||
getargspec = inspect.getfullargspec
|
||||
|
||||
|
||||
@pytest.mark.parametrize('language', all_languages)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
|
||||
from pre_commit.languages import docker
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages.golang import guess_go_dir
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages import pygrep
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
|
|
@ -16,7 +13,7 @@ def test_norm_version_expanduser():
|
|||
home = os.path.expanduser('~')
|
||||
if os.name == 'nt': # pragma: no cover (nt)
|
||||
path = r'~\python343'
|
||||
expected_path = r'{}\python343'.format(home)
|
||||
expected_path = fr'{home}\python343'
|
||||
else: # pragma: windows no cover
|
||||
path = '~/.pyenv/versions/3.4.3/bin/python'
|
||||
expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import pipes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit import color
|
||||
from pre_commit.logging_handler import LoggingHandler
|
||||
|
||||
|
||||
class FakeLogRecord(object):
|
||||
class FakeLogRecord:
|
||||
def __init__(self, message, levelname, levelno):
|
||||
self.message = message
|
||||
self.levelname = levelname
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import argparse
|
||||
import os.path
|
||||
|
||||
|
|
@ -27,7 +24,7 @@ def test_append_replace_default(argv, expected):
|
|||
assert parser.parse_args(argv).f == expected
|
||||
|
||||
|
||||
class Args(object):
|
||||
class Args:
|
||||
def __init__(self, **kwargs):
|
||||
kwargs.setdefault('command', 'help')
|
||||
kwargs.setdefault('config', C.CONFIG_FILE)
|
||||
|
|
@ -189,4 +186,4 @@ def test_expected_fatal_error_no_git_repo(in_tmpdir, cap_out, mock_store_dir):
|
|||
'An error has occurred: FatalError: git failed. '
|
||||
'Is it installed, and are you in a Git repository directory?'
|
||||
)
|
||||
assert cap_out_lines[-1] == 'Check the log at {}'.format(log_file)
|
||||
assert cap_out_lines[-1] == f'Check the log at {log_file}'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import tarfile
|
||||
|
||||
from pre_commit import git
|
||||
|
|
@ -46,4 +43,4 @@ def test_main(tmpdir):
|
|||
make_archives.main(('--dest', tmpdir.strpath))
|
||||
|
||||
for archive, _, _ in make_archives.REPOS:
|
||||
assert tmpdir.join('{}.tar.gz'.format(archive)).exists()
|
||||
assert tmpdir.join(f'{archive}.tar.gz').exists()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import contextlib
|
||||
import distutils.spawn
|
||||
import io
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
|
@ -42,8 +38,8 @@ def test_find_executable_not_found_none():
|
|||
def write_executable(shebang, filename='run'):
|
||||
os.mkdir('bin')
|
||||
path = os.path.join('bin', filename)
|
||||
with io.open(path, 'w') as f:
|
||||
f.write('#!{}'.format(shebang))
|
||||
with open(path, 'w') as f:
|
||||
f.write(f'#!{shebang}')
|
||||
make_executable(path)
|
||||
return path
|
||||
|
||||
|
|
@ -106,7 +102,7 @@ def test_normexe_is_a_directory(tmpdir):
|
|||
with pytest.raises(OSError) as excinfo:
|
||||
parse_shebang.normexe(exe)
|
||||
msg, = excinfo.value.args
|
||||
assert msg == 'Executable `{}` is a directory'.format(exe)
|
||||
assert msg == f'Executable `{exe}` is a directory'
|
||||
|
||||
|
||||
def test_normexe_already_full_path():
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import re
|
||||
import shutil
|
||||
|
|
@ -473,7 +470,7 @@ def _norm_pwd(path):
|
|||
# Under windows bash's temp and windows temp is different.
|
||||
# This normalizes to the bash /tmp
|
||||
return cmd_output_b(
|
||||
'bash', '-c', "cd '{}' && pwd".format(path),
|
||||
'bash', '-c', f"cd '{path}' && pwd",
|
||||
)[1].strip()
|
||||
|
||||
|
||||
|
|
@ -844,7 +841,7 @@ def test_manifest_hooks(tempdir_factory, store):
|
|||
hook = _get_hook(config, store, 'bash_hook')
|
||||
|
||||
assert hook == Hook(
|
||||
src='file://{}'.format(path),
|
||||
src=f'file://{path}',
|
||||
prefix=Prefix(mock.ANY),
|
||||
additional_dependencies=[],
|
||||
alias='',
|
||||
|
|
|
|||
|
|
@ -1,8 +1,3 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import itertools
|
||||
import os.path
|
||||
import shutil
|
||||
|
|
@ -47,7 +42,7 @@ def _test_foo_state(
|
|||
encoding='UTF-8',
|
||||
):
|
||||
assert os.path.exists(path.foo_filename)
|
||||
with io.open(path.foo_filename, encoding=encoding) as f:
|
||||
with open(path.foo_filename, encoding=encoding) as f:
|
||||
assert f.read() == foo_contents
|
||||
actual_status = get_short_git_status()['foo']
|
||||
assert status == actual_status
|
||||
|
|
@ -64,7 +59,7 @@ def test_foo_nothing_unstaged(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_something_unstaged(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write('herp\nderp\n')
|
||||
|
||||
_test_foo_state(foo_staged, 'herp\nderp\n', 'AM')
|
||||
|
|
@ -76,7 +71,7 @@ def test_foo_something_unstaged(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_does_not_crash_patch_dir_does_not_exist(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write('hello\nworld\n')
|
||||
|
||||
shutil.rmtree(patch_dir)
|
||||
|
|
@ -97,7 +92,7 @@ def test_foo_something_unstaged_diff_color_always(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS + '9\n')
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS + '9\n', 'AM')
|
||||
|
|
@ -106,7 +101,7 @@ def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
|||
_test_foo_state(foo_staged)
|
||||
|
||||
# Modify the file as part of the "pre-commit"
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'a'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'a'), 'AM')
|
||||
|
|
@ -115,7 +110,7 @@ def test_foo_both_modify_non_conflicting(foo_staged, patch_dir):
|
|||
|
||||
|
||||
def test_foo_both_modify_conflicting(foo_staged, patch_dir):
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'a'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'a'), 'AM')
|
||||
|
|
@ -124,7 +119,7 @@ def test_foo_both_modify_conflicting(foo_staged, patch_dir):
|
|||
_test_foo_state(foo_staged)
|
||||
|
||||
# Modify in the same place as the stashed diff
|
||||
with io.open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
with open(foo_staged.foo_filename, 'w') as foo_file:
|
||||
foo_file.write(FOO_CONTENTS.replace('1', 'b'))
|
||||
|
||||
_test_foo_state(foo_staged, FOO_CONTENTS.replace('1', 'b'), 'AM')
|
||||
|
|
@ -142,8 +137,8 @@ def img_staged(in_git_dir):
|
|||
|
||||
def _test_img_state(path, expected_file='img1.jpg', status='A'):
|
||||
assert os.path.exists(path.img_filename)
|
||||
with io.open(path.img_filename, 'rb') as f1:
|
||||
with io.open(get_resource_path(expected_file), 'rb') as f2:
|
||||
with open(path.img_filename, 'rb') as f1:
|
||||
with open(get_resource_path(expected_file), 'rb') as f2:
|
||||
assert f1.read() == f2.read()
|
||||
actual_status = get_short_git_status()['img.jpg']
|
||||
assert status == actual_status
|
||||
|
|
@ -248,7 +243,7 @@ def test_sub_something_unstaged(sub_staged, patch_dir):
|
|||
|
||||
def test_stage_utf8_changes(foo_staged, patch_dir):
|
||||
contents = '\u2603'
|
||||
with io.open('foo', 'w', encoding='UTF-8') as foo_file:
|
||||
with open('foo', 'w', encoding='UTF-8') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM')
|
||||
|
|
@ -260,7 +255,7 @@ def test_stage_utf8_changes(foo_staged, patch_dir):
|
|||
def test_stage_non_utf8_changes(foo_staged, patch_dir):
|
||||
contents = 'ú'
|
||||
# Produce a latin-1 diff
|
||||
with io.open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
with open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
|
|
@ -282,14 +277,14 @@ def test_non_utf8_conflicting_diff(foo_staged, patch_dir):
|
|||
# Previously, the error message (though discarded immediately) was being
|
||||
# decoded with the UTF-8 codec (causing a crash)
|
||||
contents = 'ú \n'
|
||||
with io.open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
with open('foo', 'w', encoding='latin-1') as foo_file:
|
||||
foo_file.write(contents)
|
||||
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
with staged_files_only(patch_dir):
|
||||
_test_foo_state(foo_staged)
|
||||
# Create a conflicting diff that will need to be rolled back
|
||||
with io.open('foo', 'w') as foo_file:
|
||||
with open('foo', 'w') as foo_file:
|
||||
foo_file.write('')
|
||||
_test_foo_state(foo_staged, contents, 'AM', encoding='latin-1')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
import sqlite3
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from pre_commit import git
|
||||
from pre_commit.store import _get_default_directory
|
||||
|
|
@ -53,7 +48,7 @@ def test_store_init(store):
|
|||
# Should create the store directory
|
||||
assert os.path.exists(store.directory)
|
||||
# Should create a README file indicating what the directory is about
|
||||
with io.open(os.path.join(store.directory, 'README')) as readme_file:
|
||||
with open(os.path.join(store.directory, 'README')) as readme_file:
|
||||
readme_contents = readme_file.read()
|
||||
for text_line in (
|
||||
'This directory is maintained by the pre-commit project.',
|
||||
|
|
@ -93,7 +88,7 @@ def test_clone_cleans_up_on_checkout_failure(store):
|
|||
# This raises an exception because you can't clone something that
|
||||
# doesn't exist!
|
||||
store.clone('/i_dont_exist_lol', 'fake_rev')
|
||||
assert '/i_dont_exist_lol' in six.text_type(excinfo.value)
|
||||
assert '/i_dont_exist_lol' in str(excinfo.value)
|
||||
|
||||
repo_dirs = [
|
||||
d for d in os.listdir(store.directory) if d.startswith('repo')
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os.path
|
||||
import stat
|
||||
import subprocess
|
||||
|
|
@ -17,7 +15,7 @@ from pre_commit.util import tmpdir
|
|||
|
||||
|
||||
def test_CalledProcessError_str():
|
||||
error = CalledProcessError(1, [str('exe')], 0, b'output', b'errors')
|
||||
error = CalledProcessError(1, ['exe'], 0, b'output', b'errors')
|
||||
assert str(error) == (
|
||||
"command: ['exe']\n"
|
||||
'return code: 1\n'
|
||||
|
|
@ -30,7 +28,7 @@ def test_CalledProcessError_str():
|
|||
|
||||
|
||||
def test_CalledProcessError_str_nooutput():
|
||||
error = CalledProcessError(1, [str('exe')], 0, b'', b'')
|
||||
error = CalledProcessError(1, ['exe'], 0, b'', b'')
|
||||
assert str(error) == (
|
||||
"command: ['exe']\n"
|
||||
'return code: 1\n'
|
||||
|
|
|
|||
|
|
@ -1,7 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import concurrent.futures
|
||||
import os
|
||||
import sys
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue