mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Use pyfakefs instead of real files in tests
* adjust review findings
This commit is contained in:
parent
9d0b99f39f
commit
2f4236158c
4 changed files with 20 additions and 21 deletions
|
|
@ -59,8 +59,8 @@ Attempts to load all json files to verify syntax.
|
|||
Check for files that contain merge conflict strings.
|
||||
|
||||
#### `check-number-of-lines-count`
|
||||
Check if number of lines of a file is greater than a threshold. You can
|
||||
configure this with the following commandline option:
|
||||
Check if the number of lines of a file is greater than a threshold.
|
||||
You can configure this with the following command line option:
|
||||
- `--max-lines N` - maximum number of lines allowed in a file.
|
||||
|
||||
#### `check-shebang-scripts-are-executable`
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
|
|||
default=30,
|
||||
type=int,
|
||||
action='store',
|
||||
help='Maximum allowable number of lines (default: 30)',
|
||||
help='Maximum allowed number of lines',
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
covdefaults
|
||||
coverage
|
||||
pyfakefs
|
||||
pytest
|
||||
|
|
|
|||
|
|
@ -1,31 +1,29 @@
|
|||
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')
|
||||
def test_number_of_lines_count_bad(fs):
|
||||
max_lines = 42
|
||||
|
||||
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))
|
||||
filename = 'lines_count_bad'
|
||||
line_contents = [
|
||||
f'I am the {line_number+1}. line!'
|
||||
for line_number in range(max_lines + 1)
|
||||
]
|
||||
fs.create_file(filename, contents='\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')
|
||||
def test_number_of_lines_count_good(fs):
|
||||
max_lines = 42
|
||||
|
||||
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))
|
||||
filename = 'lines_count_good'
|
||||
line_contents = [
|
||||
f'I am the {line_number+1}. line!'
|
||||
for line_number in range(max_lines)
|
||||
]
|
||||
fs.create_file(filename, contents='\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