Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added violation for multiline loops (#909)
* Added violation for multiline loops * Responded to feedback * Fixes CI * Fixes CI * Fixes CI
- Loading branch information
1 parent
46a4341
commit 9bb474b
Showing
6 changed files
with
148 additions
and
0 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 |
---|---|---|
|
@@ -125,6 +125,7 @@ | |
'WPS349': 1, | ||
'WPS350': 1, | ||
'WPS351': 1, | ||
'WPS352': 1, | ||
|
||
'WPS400': 0, | ||
'WPS401': 0, | ||
|
88 changes: 88 additions & 0 deletions
88
tests/test_visitors/test_ast/test_loops/test_loops/test_multiline_loops.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,88 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.consistency import ( | ||
MultilineLoopViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.loops import WrongLoopVisitor | ||
|
||
incorrect_loop1 = """ | ||
def wrapper(): | ||
for x in some_func(1, | ||
3): | ||
... | ||
""" | ||
|
||
incorrect_loop2 = """ | ||
def wrapper(): | ||
for x in (1, | ||
2, 3, 4): | ||
... | ||
""" | ||
|
||
incorrect_loop3 = """ | ||
while some_func(1, | ||
3): | ||
... | ||
""" | ||
|
||
correct_loop1 = """ | ||
def wrapper(): | ||
for x in (1, 2, 3, 4): | ||
... | ||
""" | ||
|
||
correct_loop2 = """ | ||
def wrapper(): | ||
for x in (1, 2, 3, 4): | ||
... | ||
return | ||
""" | ||
|
||
correct_loop3 = """ | ||
while some_func(1,3): | ||
... | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
incorrect_loop1, | ||
incorrect_loop2, | ||
incorrect_loop3, | ||
]) | ||
def test_incorrect_multiline_loops( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
mode, | ||
): | ||
"""Testing multiline loops.""" | ||
tree = parse_ast_tree(mode(code)) | ||
|
||
visitor = WrongLoopVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [MultilineLoopViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
correct_loop1, | ||
correct_loop2, | ||
correct_loop3, | ||
]) | ||
def test_correct_multiline_loops( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
mode, | ||
): | ||
"""Testing multiline loops.""" | ||
tree = parse_ast_tree(mode(code)) | ||
|
||
visitor = WrongLoopVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) |
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