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
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):
include_re, exclude_re = re.compile(include), re.compile(exclude)
return {
return [
filename for filename in filenames
if (
include_re.search(filename) and
not exclude_re.search(filename) and
os.path.lexists(filename)
)
}
]
def _filter_by_types(filenames, types, exclude_types):

View File

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