-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
5 changed files
with
158 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
103 changes: 103 additions & 0 deletions
103
tests/test_visitors/test_ast/test_conditions/test_multiline_conditions.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,103 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.best_practices import ( | ||
MultilineConditionsViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.conditions import IfStatementVisitor | ||
|
||
incorrect_conditions1 = """if some and ( | ||
other == 1 | ||
): | ||
... | ||
""" | ||
|
||
incorrect_conditions2 = """ | ||
if some or ( | ||
other == 1 | ||
): | ||
... | ||
""" | ||
|
||
incorrect_conditions3 = """if some and some_function( | ||
other, | ||
): | ||
... | ||
""" | ||
|
||
incorrect_conditions4 = """ | ||
if some or some_func( | ||
other, | ||
): | ||
... | ||
""" | ||
|
||
incorrect_conditions5 = """ | ||
if very_long_call_name( | ||
long_parameter_name=long_variable_name, | ||
): | ||
... | ||
""" | ||
|
||
correct_conditions1 = """ | ||
if some and other or something: | ||
... | ||
""" | ||
|
||
correct_conditions2 = """ | ||
if some_func(k) and (some or other): | ||
... | ||
""" | ||
|
||
correct_conditions3 = """ | ||
if (some_func(k) and some) or other in (1,2,3): | ||
... | ||
""" | ||
|
||
correct_conditions4 = """ | ||
if one: | ||
if two: | ||
... | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
incorrect_conditions1, | ||
incorrect_conditions2, | ||
incorrect_conditions3, | ||
incorrect_conditions4, | ||
incorrect_conditions5, | ||
]) | ||
def test_incorrect_multiline_conditions( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
mode, | ||
): | ||
"""Testing multiline conditions.""" | ||
tree = parse_ast_tree(mode(code)) | ||
visitor = IfStatementVisitor(default_options, tree=tree) | ||
visitor.run() | ||
assert_errors(visitor, [MultilineConditionsViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
correct_conditions1, | ||
correct_conditions2, | ||
correct_conditions3, | ||
correct_conditions4, | ||
]) | ||
def test_correct_multiline_conditions( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
mode, | ||
): | ||
"""Testing multiline conditions.""" | ||
tree = parse_ast_tree(mode(code)) | ||
visitor = IfStatementVisitor(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