mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-30 02:16:52 +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:
|
||||
- id: pyupgrade
|
||||
- repo: https://github.com/asottile/add-trailing-comma
|
||||
sha: v0.3.0
|
||||
sha: v0.4.1
|
||||
hooks:
|
||||
- id: add-trailing-comma
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ def is_on_branch(protected):
|
|||
def main(argv=[]):
|
||||
parser = argparse.ArgumentParser()
|
||||
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)
|
||||
|
||||
return int(is_on_branch(args.branch))
|
||||
|
|
|
|||
|
|
@ -7,26 +7,30 @@ import pytest
|
|||
from pre_commit_hooks.check_executables_have_shebangs import main
|
||||
|
||||
|
||||
@pytest.mark.parametrize('content', (
|
||||
b'#!/bin/bash\nhello world\n',
|
||||
b'#!/usr/bin/env python3.6',
|
||||
b'#!python',
|
||||
'#!☃'.encode('UTF-8'),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
'content', (
|
||||
b'#!/bin/bash\nhello world\n',
|
||||
b'#!/usr/bin/env python3.6',
|
||||
b'#!python',
|
||||
'#!☃'.encode('UTF-8'),
|
||||
),
|
||||
)
|
||||
def test_has_shebang(content, tmpdir):
|
||||
path = tmpdir.join('path')
|
||||
path.write(content, 'wb')
|
||||
assert main((path.strpath,)) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('content', (
|
||||
b'',
|
||||
b' #!python\n',
|
||||
b'\n#!python\n',
|
||||
b'python\n',
|
||||
'☃'.encode('UTF-8'),
|
||||
@pytest.mark.parametrize(
|
||||
'content', (
|
||||
b'',
|
||||
b' #!python\n',
|
||||
b'\n#!python\n',
|
||||
b'python\n',
|
||||
'☃'.encode('UTF-8'),
|
||||
|
||||
))
|
||||
),
|
||||
)
|
||||
def test_bad_shebang(content, tmpdir, capsys):
|
||||
path = tmpdir.join('path')
|
||||
path.write(content, 'wb')
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ from pre_commit_hooks.check_json import check_json
|
|||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('bad_json.notjson', 1),
|
||||
('bad_json_latin1.nonjson', 1),
|
||||
('ok_json.json', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('bad_json.notjson', 1),
|
||||
('bad_json_latin1.nonjson', 1),
|
||||
('ok_json.json', 0),
|
||||
),
|
||||
)
|
||||
def test_check_json(capsys, filename, expected_retval):
|
||||
ret = check_json([get_resource_path(filename)])
|
||||
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.parametrize(('filename', 'expected_retval'), (
|
||||
('broken_symlink', 1),
|
||||
('working_symlink', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('broken_symlink', 1),
|
||||
('working_symlink', 0),
|
||||
),
|
||||
)
|
||||
def test_check_symlinks(filename, expected_retval):
|
||||
ret = check_symlinks([get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ from pre_commit_hooks.check_xml import check_xml
|
|||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('bad_xml.notxml', 1),
|
||||
('ok_xml.xml', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('bad_xml.notxml', 1),
|
||||
('ok_xml.xml', 0),
|
||||
),
|
||||
)
|
||||
def test_check_xml(filename, expected_retval):
|
||||
ret = check_xml([get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
|
|
|||
|
|
@ -4,10 +4,12 @@ from pre_commit_hooks.check_yaml import check_yaml
|
|||
from testing.util import get_resource_path
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('bad_yaml.notyaml', 1),
|
||||
('ok_yaml.yaml', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('bad_yaml.notyaml', 1),
|
||||
('ok_yaml.yaml', 0),
|
||||
),
|
||||
)
|
||||
def test_check_yaml(filename, expected_retval):
|
||||
ret = check_yaml([get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
|
|
|||
|
|
@ -10,30 +10,36 @@ from testing.util import get_resource_path
|
|||
|
||||
@pytest.fixture
|
||||
def ast_with_no_debug_imports():
|
||||
return ast.parse("""
|
||||
return ast.parse(
|
||||
"""
|
||||
import foo
|
||||
import bar
|
||||
import baz
|
||||
from foo import bar
|
||||
""")
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ast_with_debug_import_form_1():
|
||||
return ast.parse("""
|
||||
return ast.parse(
|
||||
"""
|
||||
|
||||
import ipdb; ipdb.set_trace()
|
||||
|
||||
""")
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ast_with_debug_import_form_2():
|
||||
return ast.parse("""
|
||||
return ast.parse(
|
||||
"""
|
||||
|
||||
from pudb import set_trace; set_trace()
|
||||
|
||||
""")
|
||||
""",
|
||||
)
|
||||
|
||||
|
||||
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'},
|
||||
),
|
||||
('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',
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,35 +17,41 @@ def test_parse_indent():
|
|||
parse_indent('-2')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 1),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 1),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 0),
|
||||
),
|
||||
)
|
||||
def test_pretty_format_json(filename, expected_retval):
|
||||
ret = pretty_format_json([get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 0),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 0),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 0),
|
||||
),
|
||||
)
|
||||
def test_unsorted_pretty_format_json(filename, expected_retval):
|
||||
ret = pretty_format_json(['--no-sort-keys', get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 1),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 1),
|
||||
('tab_pretty_formatted_json.json', 0),
|
||||
))
|
||||
@pytest.mark.parametrize(
|
||||
('filename', 'expected_retval'), (
|
||||
('not_pretty_formatted_json.json', 1),
|
||||
('unsorted_pretty_formatted_json.json', 1),
|
||||
('non_ascii_pretty_formatted_json.json', 1),
|
||||
('pretty_formatted_json.json', 1),
|
||||
('tab_pretty_formatted_json.json', 0),
|
||||
),
|
||||
)
|
||||
def test_tab_pretty_format_json(filename, expected_retval):
|
||||
ret = pretty_format_json(['--indent', '\t', get_resource_path(filename)])
|
||||
assert ret == expected_retval
|
||||
|
|
|
|||
|
|
@ -22,16 +22,20 @@ TESTS = (
|
|||
# Docstring
|
||||
('""" Foo """', '""" Foo """', 0),
|
||||
(
|
||||
textwrap.dedent("""
|
||||
textwrap.dedent(
|
||||
"""
|
||||
x = " \\
|
||||
foo \\
|
||||
"\n
|
||||
"""),
|
||||
textwrap.dedent("""
|
||||
""",
|
||||
),
|
||||
textwrap.dedent(
|
||||
"""
|
||||
x = ' \\
|
||||
foo \\
|
||||
'\n
|
||||
"""),
|
||||
""",
|
||||
),
|
||||
1,
|
||||
),
|
||||
('"foo""bar"', "'foo''bar'", 1),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue