double-quote-string-fixer

This commit is contained in:
Anthony Sottile 2019-02-11 19:57:37 -08:00
parent 4575652bd2
commit 8626e266dd
8 changed files with 27 additions and 26 deletions

View File

@ -10,6 +10,7 @@ repos:
- id: check-yaml
- id: debug-statements
- id: name-tests-test
- id: double-quote-string-fixer
- id: requirements-txt-fixer
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.1

View File

@ -147,5 +147,5 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
return retv
if __name__ == "__main__":
if __name__ == '__main__':
exit(main())

View File

@ -115,9 +115,9 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
new_lines = sort(lines)
if lines != new_lines:
print("Fixing file `{filename}`".format(filename=filename))
print('Fixing file `{filename}`'.format(filename=filename))
f.seek(0)
f.write("\n".join(new_lines) + "\n")
f.write('\n'.join(new_lines) + '\n')
f.truncate()
retval = 1

View File

@ -69,7 +69,7 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
for ext in md_exts:
if any(c in ext[1:] for c in r'./\:'):
parser.error(
"bad --markdown-linebreak-ext extension {!r} (has . / \\ :)\n"
'bad --markdown-linebreak-ext extension {!r} (has . / \\ :)\n'
" (probably filename; use '--markdown-linebreak-ext=EXT')"
.format(ext),
)

View File

@ -47,36 +47,36 @@ def visitor():
# see #285
('x[0]()', []),
# complex
("0j", []),
("complex()", [Call('complex', 1, 0)]),
("complex(0, 0)", []),
('0j', []),
('complex()', [Call('complex', 1, 0)]),
('complex(0, 0)', []),
("complex('0+0j')", []),
('builtins.complex()', []),
# float
("0.0", []),
("float()", [Call('float', 1, 0)]),
('0.0', []),
('float()', [Call('float', 1, 0)]),
("float('0.0')", []),
('builtins.float()', []),
# int
("0", []),
("int()", [Call('int', 1, 0)]),
('0', []),
('int()', [Call('int', 1, 0)]),
("int('0')", []),
('builtins.int()', []),
# list
("[]", []),
("list()", [Call('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()", [Call('str', 1, 0)]),
('str()', [Call('str', 1, 0)]),
("str('0')", []),
('builtins.str()', []),
# tuple
("()", []),
("tuple()", [Call('tuple', 1, 0)]),
('()', []),
('tuple()', [Call('tuple', 1, 0)]),
("tuple('abc')", []),
("tuple([c for c in 'abc'])", []),
("tuple(c for c in 'abc')", []),
@ -91,9 +91,9 @@ def test_non_dict_exprs(visitor, expression, calls):
@pytest.mark.parametrize(
('expression', 'calls'),
[
("{}", []),
("dict()", [Call('dict', 1, 0)]),
("dict(a=1, b=2, c=3)", []),
('{}', []),
('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)]])", []),
("dict((k, v) for k, v in [('a', 1), ('b', 2), ('c', 3)])", []),
@ -108,8 +108,8 @@ def test_dict_allow_kwargs_exprs(visitor, expression, calls):
@pytest.mark.parametrize(
('expression', 'calls'),
[
("dict()", [Call('dict', 1, 0)]),
("dict(a=1, b=2, c=3)", [Call('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()', []),
],

View File

@ -123,7 +123,7 @@ def test_non_existent_credentials(mock_secrets_env, mock_secrets_file, capsys):
mock_secrets_file.return_value = set()
ret = main((
get_resource_path('aws_config_without_secrets.ini'),
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
'--credentials-file=testing/resources/credentailsfilethatdoesntexist',
))
assert ret == 2
out, _ = capsys.readouterr()
@ -143,7 +143,7 @@ def test_non_existent_credentials_with_allow_flag(
mock_secrets_file.return_value = set()
ret = main((
get_resource_path('aws_config_without_secrets.ini'),
"--credentials-file=testing/resources/credentailsfilethatdoesntexist",
"--allow-missing-credentials",
'--credentials-file=testing/resources/credentailsfilethatdoesntexist',
'--allow-missing-credentials',
))
assert ret == 0

View File

@ -41,7 +41,7 @@ def test_unsorted_main(filename, expected_retval):
assert ret == expected_retval
@pytest.mark.skipif(PY2, reason="Requires Python3")
@pytest.mark.skipif(PY2, reason='Requires Python3')
@pytest.mark.parametrize(
('filename', 'expected_retval'), (
('not_pretty_formatted_json.json', 1),

View File

@ -45,7 +45,7 @@ def test_integration_good_bad_lines(tmpdir, bad_lines, good_lines, retval):
file_path = os.path.join(tmpdir.strpath, 'foo.yaml')
with open(file_path, 'w') as f:
f.write("\n".join(bad_lines) + "\n")
f.write('\n'.join(bad_lines) + '\n')
assert main([file_path]) == retval