Change how we apply lazy to the git hook

This commit is contained in:
Ian Cordasco 2016-10-24 18:29:45 -05:00
parent 0285359a14
commit 941896218d
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
2 changed files with 36 additions and 4 deletions

View file

@ -140,11 +140,14 @@ def make_temporary_directory_from(destination, directory):
def find_modified_files(lazy):
diff_index = piped_process(
['git', 'diff-index', '' if lazy else '--cached', '--name-only',
'--diff-filter=ACMRTUXB', 'HEAD'],
)
diff_index_cmd = [
'git', 'diff-index', '--cached', '--name-only',
'--diff-filter=ACMRTUXB', 'HEAD'
]
if lazy:
diff_index_cmd.remove('--cached')
diff_index = piped_process(diff_index_cmd)
(stdout, _) = diff_index.communicate()
stdout = to_text(stdout)
return stdout.splitlines()

29
tests/unit/test_git.py Normal file
View file

@ -0,0 +1,29 @@
"""Tests around functionality in the git integration."""
import mock
import pytest
from flake8.main import git
@pytest.mark.parametrize('lazy', [True, False])
def test_find_modified_files(lazy):
"""Confirm our logic for listing modified files."""
if lazy:
# Here --cached is missing
call = [
'git', 'diff-index', '--name-only', '--diff-filter=ACMRTUXB',
'HEAD'
]
else:
call = [
'git', 'diff-index', '--cached', '--name-only',
'--diff-filter=ACMRTUXB', 'HEAD'
]
mocked_popen = mock.Mock()
mocked_popen.communicate.return_value = ('', '')
with mock.patch('flake8.main.git.piped_process') as piped_process:
piped_process.return_value = mocked_popen
git.find_modified_files(lazy)
piped_process.assert_called_once_with(call)