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:
wanghui 2016-11-22 10:55:35 +08:00
parent a52aedc0a0
commit 23be44ea50
No known key found for this signature in database
GPG key ID: 9DD1E28DBFC06C26
2 changed files with 20 additions and 1 deletions

View file

@ -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"
])