-
-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
290 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ | |
'WPS352': 1, | ||
'WPS353': 1, | ||
'WPS354': 1, | ||
'WPS355': 1, | ||
|
||
'WPS400': 0, | ||
'WPS401': 0, | ||
|
180 changes: 180 additions & 0 deletions
180
tests/test_visitors/test_tokenize/test_statements/test_bracket_empty_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.consistency import ( | ||
BracketBlankLineViolation, | ||
) | ||
from wemake_python_styleguide.visitors.tokenize.statements import ( | ||
BracketLocationVisitor, | ||
) | ||
|
||
# Correct: | ||
|
||
correct_empty_module = '' | ||
correct_single_line = 'arr = []' | ||
correct_single_line_items = 'arr = [1, 2, 3]' | ||
correct_single_line_call = 'some(1, 2, 3)' | ||
|
||
correct_method = """ | ||
class Some(object): | ||
''' | ||
Dco. | ||
Some [ | ||
Example, | ||
] | ||
''' | ||
def __init__(self, node=None, text: Optional[str] = None) -> None: | ||
... | ||
""" | ||
|
||
correct_blank_line_in_middle_list = """ | ||
arr = [ | ||
1, | ||
2, | ||
] | ||
""" | ||
|
||
correct_blank_line_in_middle_dict = """ | ||
arr = { | ||
1: | ||
2, | ||
} | ||
""" | ||
|
||
correct_blank_line_in_middle_parens = """ | ||
arr = ( | ||
1, | ||
2, | ||
) | ||
""" | ||
|
||
correct_comment_start_of_list = """ | ||
arr = [ | ||
# comment | ||
1, | ||
2, | ||
] | ||
""" | ||
|
||
correct_comment_in_middle_of_list = """ | ||
arr = [ | ||
1, | ||
# comment | ||
2, | ||
] | ||
""" | ||
|
||
# Wrong: | ||
|
||
wrong_blank_line_at_start_list = """ | ||
some = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
wrong_blank_line_at_end_list = """ | ||
some = [ | ||
1, | ||
2, | ||
3, | ||
] | ||
""" | ||
|
||
wrong_blank_line_after_comment = """ | ||
extra_new_line = [ # some | ||
'wrong', | ||
] | ||
""" | ||
|
||
wrong_blank_line_at_start_dict = """ | ||
arr = { | ||
1: 2, | ||
} | ||
""" | ||
|
||
wrong_blank_line_at_end_dict = """ | ||
arr = { | ||
1: 2, | ||
} | ||
""" | ||
|
||
wrong_blank_line_at_start_parens = """ | ||
arr = ( | ||
1, | ||
2, | ||
) | ||
""" | ||
|
||
wrong_blank_line_at_end_parens = """ | ||
arr = ( | ||
1, 2, | ||
) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
correct_empty_module, | ||
correct_single_line, | ||
correct_single_line_call, | ||
correct_single_line_items, | ||
correct_method, | ||
correct_blank_line_in_middle_list, | ||
correct_blank_line_in_middle_dict, | ||
correct_blank_line_in_middle_parens, | ||
correct_comment_start_of_list, | ||
correct_comment_in_middle_of_list, | ||
]) | ||
def test_correct_blank_lines( | ||
parse_tokens, | ||
assert_errors, | ||
default_options, | ||
code, | ||
): | ||
"""Ensures that correct blank lines work.""" | ||
file_tokens = parse_tokens(code) | ||
|
||
visitor = BracketLocationVisitor(default_options, file_tokens=file_tokens) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
wrong_blank_line_at_start_list, | ||
wrong_blank_line_at_end_list, | ||
wrong_blank_line_after_comment, | ||
wrong_blank_line_at_start_dict, | ||
wrong_blank_line_at_end_dict, | ||
wrong_blank_line_at_start_parens, | ||
wrong_blank_line_at_end_parens, | ||
]) | ||
def test_wrong_blank_lines( | ||
parse_tokens, | ||
assert_errors, | ||
default_options, | ||
code, | ||
): | ||
"""Ensures that incorrect blank lines raise a warning.""" | ||
file_tokens = parse_tokens(code) | ||
|
||
visitor = BracketLocationVisitor(default_options, file_tokens=file_tokens) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [BracketBlankLineViolation]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.