diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9467acf..9c48896 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/pre_commit_hooks/no_commit_to_branch.py b/pre_commit_hooks/no_commit_to_branch.py index 4aa3535..22ee95e 100644 --- a/pre_commit_hooks/no_commit_to_branch.py +++ b/pre_commit_hooks/no_commit_to_branch.py @@ -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)) diff --git a/tests/check_executables_have_shebangs_test.py b/tests/check_executables_have_shebangs_test.py index 0e28986..0cb9dcf 100644 --- a/tests/check_executables_have_shebangs_test.py +++ b/tests/check_executables_have_shebangs_test.py @@ -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') diff --git a/tests/check_json_test.py b/tests/check_json_test.py index 996bfbb..6ba26c1 100644 --- a/tests/check_json_test.py +++ b/tests/check_json_test.py @@ -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 diff --git a/tests/check_symlinks_test.py b/tests/check_symlinks_test.py index 4b11e71..19bb5b4 100644 --- a/tests/check_symlinks_test.py +++ b/tests/check_symlinks_test.py @@ -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 diff --git a/tests/check_xml_test.py b/tests/check_xml_test.py index 99b0902..84e365d 100644 --- a/tests/check_xml_test.py +++ b/tests/check_xml_test.py @@ -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 diff --git a/tests/check_yaml_test.py b/tests/check_yaml_test.py index c145fdc..73d6593 100644 --- a/tests/check_yaml_test.py +++ b/tests/check_yaml_test.py @@ -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 diff --git a/tests/debug_statement_hook_test.py b/tests/debug_statement_hook_test.py index 7891eac..6d8d7d8 100644 --- a/tests/debug_statement_hook_test.py +++ b/tests/debug_statement_hook_test.py @@ -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): diff --git a/tests/detect_aws_credentials_test.py b/tests/detect_aws_credentials_test.py index beb382f..978e9b0 100644 --- a/tests/detect_aws_credentials_test.py +++ b/tests/detect_aws_credentials_test.py @@ -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', { diff --git a/tests/pretty_format_json_test.py b/tests/pretty_format_json_test.py index 62e37f1..eeef65b 100644 --- a/tests/pretty_format_json_test.py +++ b/tests/pretty_format_json_test.py @@ -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 diff --git a/tests/string_fixer_test.py b/tests/string_fixer_test.py index 0429b95..a65213b 100644 --- a/tests/string_fixer_test.py +++ b/tests/string_fixer_test.py @@ -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),