mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
Use default flake8 config
This commit is contained in:
parent
634383cffd
commit
4575652bd2
16 changed files with 119 additions and 81 deletions
|
|
@ -2,9 +2,9 @@ import ast
|
|||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.check_builtin_literals import BuiltinTypeCall
|
||||
from pre_commit_hooks.check_builtin_literals import BuiltinTypeVisitor
|
||||
from pre_commit_hooks.check_builtin_literals import Call
|
||||
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
|
||||
|
|
@ -38,7 +38,7 @@ t1 = ()
|
|||
|
||||
@pytest.fixture
|
||||
def visitor():
|
||||
return BuiltinTypeVisitor()
|
||||
return Visitor()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -48,35 +48,35 @@ def visitor():
|
|||
('x[0]()', []),
|
||||
# complex
|
||||
("0j", []),
|
||||
("complex()", [BuiltinTypeCall('complex', 1, 0)]),
|
||||
("complex()", [Call('complex', 1, 0)]),
|
||||
("complex(0, 0)", []),
|
||||
("complex('0+0j')", []),
|
||||
('builtins.complex()', []),
|
||||
# float
|
||||
("0.0", []),
|
||||
("float()", [BuiltinTypeCall('float', 1, 0)]),
|
||||
("float()", [Call('float', 1, 0)]),
|
||||
("float('0.0')", []),
|
||||
('builtins.float()', []),
|
||||
# int
|
||||
("0", []),
|
||||
("int()", [BuiltinTypeCall('int', 1, 0)]),
|
||||
("int()", [Call('int', 1, 0)]),
|
||||
("int('0')", []),
|
||||
('builtins.int()', []),
|
||||
# list
|
||||
("[]", []),
|
||||
("list()", [BuiltinTypeCall('list', 1, 0)]),
|
||||
("list()", [Call('list', 1, 0)]),
|
||||
("list('abc')", []),
|
||||
("list([c for c in 'abc'])", []),
|
||||
("list(c for c in 'abc')", []),
|
||||
('builtins.list()', []),
|
||||
# str
|
||||
("''", []),
|
||||
("str()", [BuiltinTypeCall('str', 1, 0)]),
|
||||
("str()", [Call('str', 1, 0)]),
|
||||
("str('0')", []),
|
||||
('builtins.str()', []),
|
||||
# tuple
|
||||
("()", []),
|
||||
("tuple()", [BuiltinTypeCall('tuple', 1, 0)]),
|
||||
("tuple()", [Call('tuple', 1, 0)]),
|
||||
("tuple('abc')", []),
|
||||
("tuple([c for c in 'abc'])", []),
|
||||
("tuple(c for c in 'abc')", []),
|
||||
|
|
@ -92,7 +92,7 @@ def test_non_dict_exprs(visitor, expression, calls):
|
|||
('expression', 'calls'),
|
||||
[
|
||||
("{}", []),
|
||||
("dict()", [BuiltinTypeCall('dict', 1, 0)]),
|
||||
("dict()", [Call('dict', 1, 0)]),
|
||||
("dict(a=1, b=2, c=3)", []),
|
||||
("dict(**{'a': 1, 'b': 2, 'c': 3})", []),
|
||||
("dict([(k, v) for k, v in [('a', 1), ('b', 2), ('c', 3)]])", []),
|
||||
|
|
@ -108,20 +108,22 @@ def test_dict_allow_kwargs_exprs(visitor, expression, calls):
|
|||
@pytest.mark.parametrize(
|
||||
('expression', 'calls'),
|
||||
[
|
||||
("dict()", [BuiltinTypeCall('dict', 1, 0)]),
|
||||
("dict(a=1, b=2, c=3)", [BuiltinTypeCall('dict', 1, 0)]),
|
||||
("dict(**{'a': 1, 'b': 2, 'c': 3})", [BuiltinTypeCall('dict', 1, 0)]),
|
||||
("dict()", [Call('dict', 1, 0)]),
|
||||
("dict(a=1, b=2, c=3)", [Call('dict', 1, 0)]),
|
||||
("dict(**{'a': 1, 'b': 2, 'c': 3})", [Call('dict', 1, 0)]),
|
||||
('builtins.dict()', []),
|
||||
],
|
||||
)
|
||||
def test_dict_no_allow_kwargs_exprs(expression, calls):
|
||||
visitor = BuiltinTypeVisitor(allow_dict_kwargs=False)
|
||||
visitor = Visitor(allow_dict_kwargs=False)
|
||||
visitor.visit(ast.parse(expression))
|
||||
assert visitor.builtin_type_calls == calls
|
||||
|
||||
|
||||
def test_ignore_constructors():
|
||||
visitor = BuiltinTypeVisitor(ignore=('complex', 'dict', 'float', 'int', 'list', 'str', 'tuple'))
|
||||
visitor = Visitor(ignore=(
|
||||
'complex', 'dict', 'float', 'int', 'list', 'str', 'tuple',
|
||||
))
|
||||
visitor.visit(ast.parse(BUILTIN_CONSTRUCTORS))
|
||||
assert visitor.builtin_type_calls == []
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
from mock import patch
|
||||
|
||||
from pre_commit_hooks.detect_aws_credentials import get_aws_credential_files_from_env
|
||||
from pre_commit_hooks.detect_aws_credentials import get_aws_cred_files_from_env
|
||||
from pre_commit_hooks.detect_aws_credentials import get_aws_secrets_from_env
|
||||
from pre_commit_hooks.detect_aws_credentials import get_aws_secrets_from_file
|
||||
from pre_commit_hooks.detect_aws_credentials import main
|
||||
|
|
@ -35,9 +35,8 @@ from testing.util import get_resource_path
|
|||
),
|
||||
)
|
||||
def test_get_aws_credentials_file_from_env(env_vars, values):
|
||||
"""Test that reading credential files names from environment variables works."""
|
||||
with patch.dict('os.environ', env_vars, clear=True):
|
||||
assert get_aws_credential_files_from_env() == values
|
||||
assert get_aws_cred_files_from_env() == values
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -107,12 +106,11 @@ def test_get_aws_secrets_from_file(filename, expected_keys):
|
|||
),
|
||||
)
|
||||
def test_detect_aws_credentials(filename, expected_retval):
|
||||
"""Test if getting configured AWS secrets from files to be checked in works."""
|
||||
|
||||
# with a valid credentials file
|
||||
ret = main((
|
||||
get_resource_path(filename),
|
||||
"--credentials-file=testing/resources/aws_config_with_multiple_sections.ini",
|
||||
'--credentials-file',
|
||||
'testing/resources/aws_config_with_multiple_sections.ini',
|
||||
))
|
||||
assert ret == expected_retval
|
||||
|
||||
|
|
@ -138,8 +136,9 @@ def test_non_existent_credentials(mock_secrets_env, mock_secrets_file, capsys):
|
|||
|
||||
@patch('pre_commit_hooks.detect_aws_credentials.get_aws_secrets_from_file')
|
||||
@patch('pre_commit_hooks.detect_aws_credentials.get_aws_secrets_from_env')
|
||||
def test_non_existent_credentials_with_allow_flag(mock_secrets_env, mock_secrets_file):
|
||||
"""Test behavior with no configured AWS secrets and flag to allow when missing."""
|
||||
def test_non_existent_credentials_with_allow_flag(
|
||||
mock_secrets_env, mock_secrets_file,
|
||||
):
|
||||
mock_secrets_env.return_value = set()
|
||||
mock_secrets_file.return_value = set()
|
||||
ret = main((
|
||||
|
|
|
|||
|
|
@ -57,7 +57,10 @@ def test_tab_main(filename, expected_retval): # pragma: no cover
|
|||
|
||||
|
||||
def test_non_ascii_main():
|
||||
ret = main(['--no-ensure-ascii', get_resource_path('non_ascii_pretty_formatted_json.json')])
|
||||
ret = main((
|
||||
'--no-ensure-ascii',
|
||||
get_resource_path('non_ascii_pretty_formatted_json.json'),
|
||||
))
|
||||
assert ret == 0
|
||||
|
||||
|
||||
|
|
@ -79,17 +82,23 @@ def test_autofix_main(tmpdir):
|
|||
|
||||
|
||||
def test_orderfile_get_pretty_format():
|
||||
ret = main(['--top-keys=alist', get_resource_path('pretty_formatted_json.json')])
|
||||
ret = main((
|
||||
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),
|
||||
))
|
||||
assert ret == 0
|
||||
|
||||
|
||||
def test_not_orderfile_get_pretty_format():
|
||||
ret = main(['--top-keys=blah', get_resource_path('pretty_formatted_json.json')])
|
||||
ret = main((
|
||||
'--top-keys=blah', get_resource_path('pretty_formatted_json.json'),
|
||||
))
|
||||
assert ret == 1
|
||||
|
||||
|
||||
def test_top_sorted_get_pretty_format():
|
||||
ret = main(['--top-keys=01-alist,alist', get_resource_path('top_sorted_json.json')])
|
||||
ret = main((
|
||||
'--top-keys=01-alist,alist', get_resource_path('top_sorted_json.json'),
|
||||
))
|
||||
assert ret == 0
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,25 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
|
|||
(b'foo\n# comment at end\n', PASS, b'foo\n# comment at end\n'),
|
||||
(b'foo\nbar\n', FAIL, b'bar\nfoo\n'),
|
||||
(b'bar\nfoo\n', PASS, b'bar\nfoo\n'),
|
||||
(b'#comment1\nfoo\n#comment2\nbar\n', FAIL, b'#comment2\nbar\n#comment1\nfoo\n'),
|
||||
(b'#comment1\nbar\n#comment2\nfoo\n', PASS, b'#comment1\nbar\n#comment2\nfoo\n'),
|
||||
(
|
||||
b'#comment1\nfoo\n#comment2\nbar\n',
|
||||
FAIL,
|
||||
b'#comment2\nbar\n#comment1\nfoo\n',
|
||||
),
|
||||
(
|
||||
b'#comment1\nbar\n#comment2\nfoo\n',
|
||||
PASS,
|
||||
b'#comment1\nbar\n#comment2\nfoo\n',
|
||||
),
|
||||
(b'#comment\n\nfoo\nbar\n', FAIL, b'#comment\n\nbar\nfoo\n'),
|
||||
(b'#comment\n\nbar\nfoo\n', PASS, b'#comment\n\nbar\nfoo\n'),
|
||||
(b'\nfoo\nbar\n', FAIL, b'bar\n\nfoo\n'),
|
||||
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
|
||||
(b'pyramid==1\npyramid-foo==2\n', PASS, b'pyramid==1\npyramid-foo==2\n'),
|
||||
(
|
||||
b'pyramid==1\npyramid-foo==2\n',
|
||||
PASS,
|
||||
b'pyramid==1\npyramid-foo==2\n',
|
||||
),
|
||||
(b'ocflib\nDjango\nPyMySQL\n', FAIL, b'Django\nocflib\nPyMySQL\n'),
|
||||
(
|
||||
b'-e git+ssh://git_url@tag#egg=ocflib\nDjango\nPyMySQL\n',
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ def test_main_one_fails():
|
|||
|
||||
|
||||
def test_main_django_all_pass():
|
||||
ret = main(['--django', 'tests.py', 'test_foo.py', 'test_bar.py', 'tests/test_baz.py'])
|
||||
ret = main((
|
||||
'--django', 'tests.py', 'test_foo.py', 'test_bar.py',
|
||||
'tests/test_baz.py',
|
||||
))
|
||||
assert ret == 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue