diff --git a/README.md b/README.md index 7207881..10e2e9d 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/pre_commit_hooks/check_number_of_lines_count.py b/pre_commit_hooks/check_number_of_lines_count.py index f3443d0..44b495b 100755 --- a/pre_commit_hooks/check_number_of_lines_count.py +++ b/pre_commit_hooks/check_number_of_lines_count.py @@ -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) diff --git a/requirements-dev.txt b/requirements-dev.txt index 0c5a37e..9eecc42 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,3 +1,4 @@ covdefaults coverage +pyfakefs pytest diff --git a/tests/check_number_of_lines_count_test.py b/tests/check_number_of_lines_count_test.py index 06f0a57..962b816 100644 --- a/tests/check_number_of_lines_count_test.py +++ b/tests/check_number_of_lines_count_test.py @@ -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