mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
run-sub-hooks hook added
This commit is contained in:
parent
5df1a4bf6f
commit
ec577f284a
5 changed files with 130 additions and 0 deletions
55
tests/run_sub_hooks_test.py
Normal file
55
tests/run_sub_hooks_test.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import re
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.run_sub_hooks import main
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_sub_dir(temp_git_dir):
|
||||
"""Temporary git subdirectory with pre-commit config inside of it"""
|
||||
with temp_git_dir.as_cwd():
|
||||
sub_dir = temp_git_dir.mkdir('subdir')
|
||||
sub_dir.join('.pre-commit-config.yaml').write(
|
||||
"""\
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v2.0.0
|
||||
hooks:
|
||||
- id: trailing-whitespace\
|
||||
"""
|
||||
)
|
||||
yield sub_dir
|
||||
|
||||
|
||||
INFO_PATTERN = re.compile(r'^\s*(\[INFO\] [^\n]+\n)+', flags=re.M)
|
||||
|
||||
|
||||
def test_clean_run(temp_sub_dir, capfd):
|
||||
assert main(['--target', str(temp_sub_dir), '--all-files']) == 0
|
||||
captured = capfd.readouterr()
|
||||
assert ( # noqa: E501
|
||||
INFO_PATTERN.sub('', captured.out) ==
|
||||
"""\
|
||||
Trim Trailing Whitespace.................................................Passed
|
||||
"""
|
||||
)
|
||||
assert captured.err == ''
|
||||
|
||||
|
||||
def test_only_sub_dir_files_when_all_files(temp_git_dir, temp_sub_dir, capfd):
|
||||
temp_git_dir.join('file1.yaml').write('some trailing whitespace -> ')
|
||||
temp_sub_dir.join('file2.yaml').write('some trailing whitespace -> ')
|
||||
assert main(['--target', str(temp_sub_dir), '--all-files']) == 1
|
||||
captured = capfd.readouterr()
|
||||
assert ( # noqa: E501
|
||||
INFO_PATTERN.sub('', captured.out) ==
|
||||
"""\
|
||||
Trim Trailing Whitespace.................................................Failed
|
||||
hookid: trailing-whitespace
|
||||
|
||||
Fixing subdir/file2.yaml
|
||||
|
||||
"""
|
||||
)
|
||||
assert captured.err == ''
|
||||
Loading…
Add table
Add a link
Reference in a new issue