mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 13:36:54 +00:00
Fix git hook checks all the staged files
I think because of this commit:
78e8165b06
The git hook will check all the staged files even it is not a Python source files.
This commit try to fix this and issue #271.
This commit is contained in:
parent
a52aedc0a0
commit
23be44ea50
2 changed files with 20 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
"""
|
||||
import contextlib
|
||||
import fnmatch
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
|
|
@ -40,7 +41,8 @@ def hook(lazy=False, strict=False):
|
|||
from flake8.main import application
|
||||
app = application.Application()
|
||||
with make_temporary_directory() as tempdir:
|
||||
filepaths = list(copy_indexed_files_to(tempdir, lazy))
|
||||
filepaths = [x for x in list(copy_indexed_files_to(tempdir, lazy))
|
||||
if fnmatch.fnmatch(x, '*.py')]
|
||||
app.initialize(['.'])
|
||||
app.options.exclude = update_excludes(app.options.exclude, tempdir)
|
||||
app.run_checks(filepaths)
|
||||
|
|
|
|||
|
|
@ -27,3 +27,20 @@ def test_find_modified_files(lazy):
|
|||
git.find_modified_files(lazy)
|
||||
|
||||
piped_process.assert_called_once_with(call)
|
||||
|
||||
|
||||
@mock.patch("flake8.main.git.copy_indexed_files_to")
|
||||
def test_only_py_files(mock_files):
|
||||
"""Confirm only run checks on Python source file."""
|
||||
mock_files.return_value = [
|
||||
"/tmp/xxx/test.py",
|
||||
"/tmp/xxx/test.html",
|
||||
"/tmp/xxx/test.txt",
|
||||
]
|
||||
|
||||
spec = "flake8.main.application.Application.run_checks"
|
||||
with mock.patch(spec) as mock_run:
|
||||
git.hook(lazy=False)
|
||||
mock_run.assert_called_once_with([
|
||||
"/tmp/xxx/test.py"
|
||||
])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue