mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Add hook to check the number of allowed lines
This commit is contained in:
parent
1ca4ceba96
commit
9d0b99f39f
4 changed files with 72 additions and 0 deletions
31
tests/check_number_of_lines_count_test.py
Normal file
31
tests/check_number_of_lines_count_test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from pre_commit_hooks.check_number_of_lines_count import main
|
||||
|
||||
|
||||
def test_number_of_lines_count_bad(tmpdir):
|
||||
max_lines = 30
|
||||
line_contents = []
|
||||
filename = tmpdir.join('lines_count_bad')
|
||||
|
||||
for line_number in range(max_lines + 1):
|
||||
line_contents.append(f'I am the {line_number+1}. line!')
|
||||
|
||||
with open(filename, 'w') as file:
|
||||
file.write('\n'.join(line_contents))
|
||||
|
||||
ret = main([str(filename), f'--max-lines={max_lines}'])
|
||||
assert ret == 1
|
||||
|
||||
|
||||
def test_number_of_lines_count_good(tmpdir):
|
||||
max_lines = 30
|
||||
line_contents = []
|
||||
filename = tmpdir.join('lines_count_good')
|
||||
|
||||
for line_number in range(max_lines):
|
||||
line_contents.append(f'I am the {line_number+1}. line!')
|
||||
|
||||
with open(filename, 'w') as file:
|
||||
file.write('\n'.join(line_contents))
|
||||
|
||||
ret = main([str(filename), f'--max-lines={max_lines}'])
|
||||
assert ret == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue