Merging upstream version 5.0.0+dfsg.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
894e74df77
commit
e531b1b230
12 changed files with 153 additions and 26 deletions
63
tests/check_illegal_windows_names_test.py
Normal file
63
tests/check_illegal_windows_names_test.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os.path
|
||||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.check_yaml import yaml
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def hook_re():
|
||||
here = os.path.dirname(__file__)
|
||||
with open(os.path.join(here, '..', '.pre-commit-hooks.yaml')) as f:
|
||||
hook_defs = yaml.load(f)
|
||||
hook, = (
|
||||
hook
|
||||
for hook in hook_defs
|
||||
if hook['id'] == 'check-illegal-windows-names'
|
||||
)
|
||||
yield re.compile(hook['files'])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
's',
|
||||
(
|
||||
pytest.param('aux.txt', id='with ext'),
|
||||
pytest.param('aux', id='without ext'),
|
||||
pytest.param('AuX.tXt', id='capitals'),
|
||||
pytest.param('com7.dat', id='com with digit'),
|
||||
pytest.param(':', id='bare colon'),
|
||||
pytest.param('file:Zone.Identifier', id='mid colon'),
|
||||
pytest.param('path/COM¹.json', id='com with superscript'),
|
||||
pytest.param('dir/LPT³.toml', id='lpt with superscript'),
|
||||
pytest.param('with < less than', id='with less than'),
|
||||
pytest.param('Fast or Slow?.md', id='with question mark'),
|
||||
pytest.param('with "double" quotes', id='with double quotes'),
|
||||
pytest.param('with_null\x00byte', id='with null byte'),
|
||||
pytest.param('ends_with.', id='ends with period'),
|
||||
pytest.param('ends_with ', id='ends with space'),
|
||||
pytest.param('ends_with\t', id='ends with tab'),
|
||||
pytest.param('dir/ends./with.txt', id='directory ends with period'),
|
||||
pytest.param('dir/ends /with.txt', id='directory ends with space'),
|
||||
),
|
||||
)
|
||||
def test_check_illegal_windows_names_matches(hook_re, s):
|
||||
assert hook_re.search(s)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
's',
|
||||
(
|
||||
pytest.param('README.md', id='standard file'),
|
||||
pytest.param('foo.aux', id='as ext'),
|
||||
pytest.param('com.dat', id='com without digit'),
|
||||
pytest.param('.python-version', id='starts with period'),
|
||||
pytest.param(' pseudo nan', id='with spaces'),
|
||||
pytest.param('!@#$%^&;=≤\'~`¡¿€🤗', id='with allowed characters'),
|
||||
pytest.param('path.to/file.py', id='standard path'),
|
||||
),
|
||||
)
|
||||
def test_check_illegal_windows_names_does_not_match(hook_re, s):
|
||||
assert hook_re.search(s) is None
|
|
@ -82,6 +82,24 @@ def test_autofix_main(tmpdir):
|
|||
assert ret == 0
|
||||
|
||||
|
||||
def test_invalid_main(tmpdir):
|
||||
srcfile1 = tmpdir.join('not_valid_json.json')
|
||||
srcfile1.write(
|
||||
'{\n'
|
||||
' // not json\n'
|
||||
' "a": "b"\n'
|
||||
'}',
|
||||
)
|
||||
srcfile2 = tmpdir.join('to_be_json_formatted.json')
|
||||
srcfile2.write('{ "a": "b" }')
|
||||
|
||||
# it should have skipped the first file and formatted the second one
|
||||
assert main(['--autofix', str(srcfile1), str(srcfile2)]) == 1
|
||||
|
||||
# confirm second file was formatted (shouldn't trigger linter again)
|
||||
assert main([str(srcfile2)]) == 0
|
||||
|
||||
|
||||
def test_orderfile_get_pretty_format():
|
||||
ret = main((
|
||||
'--top-keys=alist', get_resource_path('pretty_formatted_json.json'),
|
||||
|
|
|
@ -82,6 +82,8 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
|
|||
),
|
||||
(b'bar\npkg-resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
|
||||
(b'foo\npkg-resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
|
||||
(b'bar\npkg_resources==0.0.0\nfoo\n', FAIL, b'bar\nfoo\n'),
|
||||
(b'foo\npkg_resources==0.0.0\nbar\n', FAIL, b'bar\nfoo\n'),
|
||||
(
|
||||
b'git+ssh://git_url@tag#egg=ocflib\nDjango\nijk\n',
|
||||
FAIL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue