Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: make too many/too few empty lines more verbose #416

Merged
merged 4 commits into from
Jan 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions conda_smithy/lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ def lintify(meta, recipe_dir=None):
# Count the number of empty lines from the end of the file
empty_lines = itertools.takewhile(lambda x: x == '', reversed(lines))
end_empty_lines_count = len(list(empty_lines))
if end_empty_lines_count != 1:
lints.append('There should be one empty line at the end of the '
'file.')
if end_empty_lines_count > 1:
lints.append('There are {} too many lines. '
'There should be one empty line at the end of the '
'file.'.format(end_empty_lines_count - 1))
elif end_empty_lines_count < 1:
lints.append('There are too few lines. There should be one empty '
'line at the end of the file.')

# 12: License family must be valid (conda-build checks for that)
try:
Expand Down
15 changes: 12 additions & 3 deletions conda_smithy/tests/test_lint_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,21 @@ def test_end_empty_line(self):
# Exactly one empty line at the end of the file
valid_content = 'extra:\n recipe-maintainers:\n - goanpeca\n'

for content in bad_contents + [valid_content]:
for content, lines in zip(bad_contents + [valid_content],
[0, 0, 0, 2, 2, 2, 3, 3, 3, 1]):
with tmp_directory() as recipe_dir:
with io.open(os.path.join(recipe_dir, 'meta.yaml'), 'w') as f:
f.write(content)
lints = linter.lintify({}, recipe_dir=recipe_dir)
expected_message = ('There should be one empty line at the '
'end of the file.')
if lines > 1:
expected_message = ('There are {} too many lines. '
'There should be one empty line '
'at the end of the '
'file.'.format(lines - 1))
else:
expected_message = ('There are too few lines. '
'There should be one empty line at'
' the end of the file.')
if content == valid_content:
self.assertNotIn(expected_message, lints)
else:
Expand Down Expand Up @@ -332,5 +340,6 @@ def test_unicode(self):
# Just run it and make sure it does not raise.
linter.main(recipe_dir)


if __name__ == '__main__':
unittest.main()