Merge pull request #767 from pre-commit/consistent_ordering

Consistent ordering of filenames
This commit is contained in:
Anthony Sottile 2018-06-11 13:27:04 -07:00 committed by GitHub
commit 31e751f4d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -38,14 +38,14 @@ def _hook_msg_start(hook, verbose):
def _filter_by_include_exclude(filenames, include, exclude): def _filter_by_include_exclude(filenames, include, exclude):
include_re, exclude_re = re.compile(include), re.compile(exclude) include_re, exclude_re = re.compile(include), re.compile(exclude)
return { return [
filename for filename in filenames filename for filename in filenames
if ( if (
include_re.search(filename) and include_re.search(filename) and
not exclude_re.search(filename) and not exclude_re.search(filename) and
os.path.lexists(filename) os.path.lexists(filename)
) )
} ]
def _filter_by_types(filenames, types, exclude_types): def _filter_by_types(filenames, types, exclude_types):

View file

@ -770,19 +770,19 @@ def test_fail_fast(
def some_filenames(): def some_filenames():
return ( return (
'.pre-commit-hooks.yaml', '.pre-commit-hooks.yaml',
'pre_commit/main.py',
'pre_commit/git.py',
'im_a_file_that_doesnt_exist.py', 'im_a_file_that_doesnt_exist.py',
'pre_commit/git.py',
'pre_commit/main.py',
) )
def test_include_exclude_base_case(some_filenames): def test_include_exclude_base_case(some_filenames):
ret = _filter_by_include_exclude(some_filenames, '', '^$') ret = _filter_by_include_exclude(some_filenames, '', '^$')
assert ret == { assert ret == [
'.pre-commit-hooks.yaml', '.pre-commit-hooks.yaml',
'pre_commit/main.py',
'pre_commit/git.py', 'pre_commit/git.py',
} 'pre_commit/main.py',
]
@xfailif_no_symlink @xfailif_no_symlink
@ -790,19 +790,19 @@ def test_matches_broken_symlink(tmpdir): # pragma: no cover (non-windows)
with tmpdir.as_cwd(): with tmpdir.as_cwd():
os.symlink('does-not-exist', 'link') os.symlink('does-not-exist', 'link')
ret = _filter_by_include_exclude({'link'}, '', '^$') ret = _filter_by_include_exclude({'link'}, '', '^$')
assert ret == {'link'} assert ret == ['link']
def test_include_exclude_total_match(some_filenames): def test_include_exclude_total_match(some_filenames):
ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$') ret = _filter_by_include_exclude(some_filenames, r'^.*\.py$', '^$')
assert ret == {'pre_commit/main.py', 'pre_commit/git.py'} assert ret == ['pre_commit/git.py', 'pre_commit/main.py']
def test_include_exclude_does_search_instead_of_match(some_filenames): def test_include_exclude_does_search_instead_of_match(some_filenames):
ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$') ret = _filter_by_include_exclude(some_filenames, r'\.yaml$', '^$')
assert ret == {'.pre-commit-hooks.yaml'} assert ret == ['.pre-commit-hooks.yaml']
def test_include_exclude_exclude_removes_files(some_filenames): def test_include_exclude_exclude_removes_files(some_filenames):
ret = _filter_by_include_exclude(some_filenames, '', r'\.py$') ret = _filter_by_include_exclude(some_filenames, '', r'\.py$')
assert ret == {'.pre-commit-hooks.yaml'} assert ret == ['.pre-commit-hooks.yaml']