pre-commit-hooks: python3.6+

This commit is contained in:
Anthony Sottile 2020-02-05 11:10:42 -08:00
parent 551d1a07b3
commit f5c42a050b
60 changed files with 291 additions and 493 deletions

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.autopep8_wrapper import main

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import distutils.spawn
import pytest
@ -78,7 +75,7 @@ xfailif_no_gitlfs = pytest.mark.xfail(
@xfailif_no_gitlfs
def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
with temp_git_dir.as_cwd():
monkeypatch.setenv(str('HOME'), str(temp_git_dir.strpath))
monkeypatch.setenv('HOME', str(temp_git_dir.strpath))
cmd_output('git', 'lfs', 'install')
temp_git_dir.join('f.py').write('a' * 10000)
cmd_output('git', 'lfs', 'track', 'f.py')
@ -90,7 +87,7 @@ def test_allows_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
@xfailif_no_gitlfs
def test_moves_with_gitlfs(temp_git_dir, monkeypatch): # pragma: no cover
with temp_git_dir.as_cwd():
monkeypatch.setenv(str('HOME'), str(temp_git_dir.strpath))
monkeypatch.setenv('HOME', str(temp_git_dir.strpath))
cmd_output('git', 'lfs', 'install')
cmd_output('git', 'lfs', 'track', 'a.bin', 'b.bin')
# First add the file we're going to move

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit_hooks.check_ast import main
from testing.util import get_resource_path

View file

@ -7,7 +7,7 @@ from pre_commit_hooks.check_builtin_literals import main
from pre_commit_hooks.check_builtin_literals import Visitor
BUILTIN_CONSTRUCTORS = '''\
from six.moves import builtins
import builtins
c1 = complex()
d1 = dict()

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit_hooks import check_byte_order_marker

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit_hooks.check_case_conflict import find_conflicting_filenames
from pre_commit_hooks.check_case_conflict import main
from pre_commit_hooks.util import cmd_output

View file

@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.check_docstring_first import check_docstring_first

View file

@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.check_executables_have_shebangs import main
@ -12,7 +8,7 @@ from pre_commit_hooks.check_executables_have_shebangs import main
b'#!/bin/bash\nhello world\n',
b'#!/usr/bin/env python3.6',
b'#!python',
'#!☃'.encode('UTF-8'),
'#!☃'.encode(),
),
)
def test_has_shebang(content, tmpdir):
@ -27,7 +23,7 @@ def test_has_shebang(content, tmpdir):
b' #!python\n',
b'\n#!python\n',
b'python\n',
''.encode('UTF-8'),
''.encode(),
),
)
@ -36,4 +32,4 @@ def test_bad_shebang(content, tmpdir, capsys):
path.write(content, 'wb')
assert main((path.strpath,)) == 1
_, stderr = capsys.readouterr()
assert stderr.startswith('{}: marked executable but'.format(path.strpath))
assert stderr.startswith(f'{path}: marked executable but')

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import os
import shutil

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit_hooks.check_toml import main

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
from pre_commit_hooks.check_vcs_permalinks import main

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.check_yaml import main

View file

@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.util import cmd_output

View file

@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import ast
from pre_commit_hooks.debug_statement_hook import Debug

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import io
import pytest
@ -129,9 +126,6 @@ def test_not_ok_input_alternate_pragma():
@pytest.mark.parametrize(
('input_s', 'expected'),
(
# Python 2 cli parameters are bytes
(b'# coding: utf-8', b'# coding: utf-8'),
# Python 3 cli parameters are text
('# coding: utf-8', b'# coding: utf-8'),
# trailing whitespace
('# coding: utf-8\n', b'# coding: utf-8'),
@ -149,7 +143,7 @@ def test_integration_alternate_pragma(tmpdir, capsys):
assert main((f.strpath, '--pragma', pragma)) == 1
assert f.read() == '# coding: utf-8\nx = 1\n'
out, _ = capsys.readouterr()
assert out == 'Added `# coding: utf-8` to {}\n'.format(f.strpath)
assert out == f'Added `# coding: utf-8` to {f.strpath}\n'
def test_crlf_ok(tmpdir):

View file

@ -1,5 +1,3 @@
from __future__ import absolute_import
import subprocess
import pytest

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.mixed_line_ending import main
@ -86,7 +83,7 @@ def test_no_fix_does_not_modify(tmpdir, capsys):
assert ret == 1
assert path.read_binary() == contents
out, _ = capsys.readouterr()
assert out == '{}: mixed line endings\n'.format(path)
assert out == f'{path}: mixed line endings\n'
def test_fix_lf(tmpdir, capsys):
@ -97,7 +94,7 @@ def test_fix_lf(tmpdir, capsys):
assert ret == 1
assert path.read_binary() == b'foo\nbar\nbaz\n'
out, _ = capsys.readouterr()
assert out == '{}: fixed mixed line endings\n'.format(path)
assert out == f'{path}: fixed mixed line endings\n'
def test_fix_crlf(tmpdir):

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.no_commit_to_branch import is_on_branch

View file

@ -2,7 +2,6 @@ import os
import shutil
import pytest
from six import PY2
from pre_commit_hooks.pretty_format_json import main
from pre_commit_hooks.pretty_format_json import parse_num_to_int
@ -42,7 +41,6 @@ def test_unsorted_main(filename, expected_retval):
assert ret == expected_retval
@pytest.mark.skipif(PY2, reason='Requires Python3')
@pytest.mark.parametrize(
('filename', 'expected_retval'), (
('not_pretty_formatted_json.json', 1),
@ -52,7 +50,7 @@ def test_unsorted_main(filename, expected_retval):
('tab_pretty_formatted_json.json', 0),
),
)
def test_tab_main(filename, expected_retval): # pragma: no cover
def test_tab_main(filename, expected_retval):
ret = main(['--indent', '\t', get_resource_path(filename)])
assert ret == expected_retval
@ -113,9 +111,9 @@ def test_diffing_output(capsys):
expected_retval = 1
a = os.path.join('a', resource_path)
b = os.path.join('b', resource_path)
expected_out = '''\
--- {}
+++ {}
expected_out = f'''\
--- {a}
+++ {b}
@@ -1,6 +1,9 @@
{{
- "foo":
@ -130,7 +128,7 @@ def test_diffing_output(capsys):
+ "blah": null,
+ "foo": "bar"
}}
'''.format(a, b)
'''
actual_retval = main([resource_path])
actual_out, actual_err = capsys.readouterr()

View file

@ -1,15 +1,10 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import io
from pre_commit_hooks.check_yaml import yaml
def test_readme_contains_all_hooks():
with io.open('README.md', encoding='UTF-8') as f:
with open('README.md', encoding='UTF-8') as f:
readme_contents = f.read()
with io.open('.pre-commit-hooks.yaml', encoding='UTF-8') as f:
with open('.pre-commit-hooks.yaml', encoding='UTF-8') as f:
hooks = yaml.load(f)
for hook in hooks:
assert '`{}`'.format(hook['id']) in readme_contents
assert f'`{hook["id"]}`' in readme_contents

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import os
import pytest

View file

@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import textwrap
import pytest

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.trailing_whitespace_fixer import main
@ -46,7 +43,7 @@ def test_fixes_markdown_files(tmpdir, ext):
'\t\n' # trailing tabs are stripped anyway
'\n ', # whitespace at the end of the file is removed
)
ret = main((path.strpath, '--markdown-linebreak-ext={}'.format(ext)))
ret = main((path.strpath, f'--markdown-linebreak-ext={ext}'))
assert ret == 1
assert path.read() == (
'foo \n'

View file

@ -1,6 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
import pytest
from pre_commit_hooks.util import CalledProcessError