mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 04:54:16 +00:00
Merge pull request #216 from pre-commit/upgrade_add_trailing_comma
Upgrade add-trailing-comma to 0.4.1
This commit is contained in:
commit
19b7f0f6ed
11 changed files with 94 additions and 63 deletions
|
|
@ -27,6 +27,6 @@
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
- repo: https://github.com/asottile/add-trailing-comma
|
- repo: https://github.com/asottile/add-trailing-comma
|
||||||
sha: v0.3.0
|
sha: v0.4.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: add-trailing-comma
|
- id: add-trailing-comma
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,8 @@ def is_on_branch(protected):
|
||||||
def main(argv=[]):
|
def main(argv=[]):
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-b', '--branch', default='master', help='branch to disallow commits to')
|
'-b', '--branch', default='master', help='branch to disallow commits to',
|
||||||
|
)
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
return int(is_on_branch(args.branch))
|
return int(is_on_branch(args.branch))
|
||||||
|
|
|
||||||
|
|
@ -7,26 +7,30 @@ import pytest
|
||||||
from pre_commit_hooks.check_executables_have_shebangs import main
|
from pre_commit_hooks.check_executables_have_shebangs import main
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('content', (
|
@pytest.mark.parametrize(
|
||||||
|
'content', (
|
||||||
b'#!/bin/bash\nhello world\n',
|
b'#!/bin/bash\nhello world\n',
|
||||||
b'#!/usr/bin/env python3.6',
|
b'#!/usr/bin/env python3.6',
|
||||||
b'#!python',
|
b'#!python',
|
||||||
'#!☃'.encode('UTF-8'),
|
'#!☃'.encode('UTF-8'),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_has_shebang(content, tmpdir):
|
def test_has_shebang(content, tmpdir):
|
||||||
path = tmpdir.join('path')
|
path = tmpdir.join('path')
|
||||||
path.write(content, 'wb')
|
path.write(content, 'wb')
|
||||||
assert main((path.strpath,)) == 0
|
assert main((path.strpath,)) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('content', (
|
@pytest.mark.parametrize(
|
||||||
|
'content', (
|
||||||
b'',
|
b'',
|
||||||
b' #!python\n',
|
b' #!python\n',
|
||||||
b'\n#!python\n',
|
b'\n#!python\n',
|
||||||
b'python\n',
|
b'python\n',
|
||||||
'☃'.encode('UTF-8'),
|
'☃'.encode('UTF-8'),
|
||||||
|
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_bad_shebang(content, tmpdir, capsys):
|
def test_bad_shebang(content, tmpdir, capsys):
|
||||||
path = tmpdir.join('path')
|
path = tmpdir.join('path')
|
||||||
path.write(content, 'wb')
|
path.write(content, 'wb')
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@ from pre_commit_hooks.check_json import check_json
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('bad_json.notjson', 1),
|
('bad_json.notjson', 1),
|
||||||
('bad_json_latin1.nonjson', 1),
|
('bad_json_latin1.nonjson', 1),
|
||||||
('ok_json.json', 0),
|
('ok_json.json', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_check_json(capsys, filename, expected_retval):
|
def test_check_json(capsys, filename, expected_retval):
|
||||||
ret = check_json([get_resource_path(filename)])
|
ret = check_json([get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(os.name == 'nt', reason='No symlink support on windows')
|
@pytest.mark.xfail(os.name == 'nt', reason='No symlink support on windows')
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('broken_symlink', 1),
|
('broken_symlink', 1),
|
||||||
('working_symlink', 0),
|
('working_symlink', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_check_symlinks(filename, expected_retval):
|
def test_check_symlinks(filename, expected_retval):
|
||||||
ret = check_symlinks([get_resource_path(filename)])
|
ret = check_symlinks([get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,12 @@ from pre_commit_hooks.check_xml import check_xml
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('bad_xml.notxml', 1),
|
('bad_xml.notxml', 1),
|
||||||
('ok_xml.xml', 0),
|
('ok_xml.xml', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_check_xml(filename, expected_retval):
|
def test_check_xml(filename, expected_retval):
|
||||||
ret = check_xml([get_resource_path(filename)])
|
ret = check_xml([get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,12 @@ from pre_commit_hooks.check_yaml import check_yaml
|
||||||
from testing.util import get_resource_path
|
from testing.util import get_resource_path
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('bad_yaml.notyaml', 1),
|
('bad_yaml.notyaml', 1),
|
||||||
('ok_yaml.yaml', 0),
|
('ok_yaml.yaml', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_check_yaml(filename, expected_retval):
|
def test_check_yaml(filename, expected_retval):
|
||||||
ret = check_yaml([get_resource_path(filename)])
|
ret = check_yaml([get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -10,30 +10,36 @@ from testing.util import get_resource_path
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ast_with_no_debug_imports():
|
def ast_with_no_debug_imports():
|
||||||
return ast.parse("""
|
return ast.parse(
|
||||||
|
"""
|
||||||
import foo
|
import foo
|
||||||
import bar
|
import bar
|
||||||
import baz
|
import baz
|
||||||
from foo import bar
|
from foo import bar
|
||||||
""")
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ast_with_debug_import_form_1():
|
def ast_with_debug_import_form_1():
|
||||||
return ast.parse("""
|
return ast.parse(
|
||||||
|
"""
|
||||||
|
|
||||||
import ipdb; ipdb.set_trace()
|
import ipdb; ipdb.set_trace()
|
||||||
|
|
||||||
""")
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ast_with_debug_import_form_2():
|
def ast_with_debug_import_form_2():
|
||||||
return ast.parse("""
|
return ast.parse(
|
||||||
|
"""
|
||||||
|
|
||||||
from pudb import set_trace; set_trace()
|
from pudb import set_trace; set_trace()
|
||||||
|
|
||||||
""")
|
""",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_returns_no_debug_statements(ast_with_no_debug_imports):
|
def test_returns_no_debug_statements(ast_with_no_debug_imports):
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,10 @@ def test_get_aws_secrets_from_env(env_vars, values):
|
||||||
{'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb'},
|
{'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb'},
|
||||||
),
|
),
|
||||||
('aws_config_with_session_token.ini', {'foo'}),
|
('aws_config_with_session_token.ini', {'foo'}),
|
||||||
('aws_config_with_secret_and_session_token.ini',
|
(
|
||||||
{'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb', 'foo'}),
|
'aws_config_with_secret_and_session_token.ini',
|
||||||
|
{'z2rpgs5uit782eapz5l1z0y2lurtsyyk6hcfozlb', 'foo'},
|
||||||
|
),
|
||||||
(
|
(
|
||||||
'aws_config_with_multiple_sections.ini',
|
'aws_config_with_multiple_sections.ini',
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,35 +17,41 @@ def test_parse_indent():
|
||||||
parse_indent('-2')
|
parse_indent('-2')
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('not_pretty_formatted_json.json', 1),
|
('not_pretty_formatted_json.json', 1),
|
||||||
('unsorted_pretty_formatted_json.json', 1),
|
('unsorted_pretty_formatted_json.json', 1),
|
||||||
('non_ascii_pretty_formatted_json.json', 1),
|
('non_ascii_pretty_formatted_json.json', 1),
|
||||||
('pretty_formatted_json.json', 0),
|
('pretty_formatted_json.json', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_pretty_format_json(filename, expected_retval):
|
def test_pretty_format_json(filename, expected_retval):
|
||||||
ret = pretty_format_json([get_resource_path(filename)])
|
ret = pretty_format_json([get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('not_pretty_formatted_json.json', 1),
|
('not_pretty_formatted_json.json', 1),
|
||||||
('unsorted_pretty_formatted_json.json', 0),
|
('unsorted_pretty_formatted_json.json', 0),
|
||||||
('non_ascii_pretty_formatted_json.json', 1),
|
('non_ascii_pretty_formatted_json.json', 1),
|
||||||
('pretty_formatted_json.json', 0),
|
('pretty_formatted_json.json', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_unsorted_pretty_format_json(filename, expected_retval):
|
def test_unsorted_pretty_format_json(filename, expected_retval):
|
||||||
ret = pretty_format_json(['--no-sort-keys', get_resource_path(filename)])
|
ret = pretty_format_json(['--no-sort-keys', get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
@pytest.mark.parametrize(
|
||||||
|
('filename', 'expected_retval'), (
|
||||||
('not_pretty_formatted_json.json', 1),
|
('not_pretty_formatted_json.json', 1),
|
||||||
('unsorted_pretty_formatted_json.json', 1),
|
('unsorted_pretty_formatted_json.json', 1),
|
||||||
('non_ascii_pretty_formatted_json.json', 1),
|
('non_ascii_pretty_formatted_json.json', 1),
|
||||||
('pretty_formatted_json.json', 1),
|
('pretty_formatted_json.json', 1),
|
||||||
('tab_pretty_formatted_json.json', 0),
|
('tab_pretty_formatted_json.json', 0),
|
||||||
))
|
),
|
||||||
|
)
|
||||||
def test_tab_pretty_format_json(filename, expected_retval):
|
def test_tab_pretty_format_json(filename, expected_retval):
|
||||||
ret = pretty_format_json(['--indent', '\t', get_resource_path(filename)])
|
ret = pretty_format_json(['--indent', '\t', get_resource_path(filename)])
|
||||||
assert ret == expected_retval
|
assert ret == expected_retval
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,20 @@ TESTS = (
|
||||||
# Docstring
|
# Docstring
|
||||||
('""" Foo """', '""" Foo """', 0),
|
('""" Foo """', '""" Foo """', 0),
|
||||||
(
|
(
|
||||||
textwrap.dedent("""
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
x = " \\
|
x = " \\
|
||||||
foo \\
|
foo \\
|
||||||
"\n
|
"\n
|
||||||
"""),
|
""",
|
||||||
textwrap.dedent("""
|
),
|
||||||
|
textwrap.dedent(
|
||||||
|
"""
|
||||||
x = ' \\
|
x = ' \\
|
||||||
foo \\
|
foo \\
|
||||||
'\n
|
'\n
|
||||||
"""),
|
""",
|
||||||
|
),
|
||||||
1,
|
1,
|
||||||
),
|
),
|
||||||
('"foo""bar"', "'foo''bar'", 1),
|
('"foo""bar"', "'foo''bar'", 1),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue