-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds
WPS241
which forbids to have too many subjects in match
stat…
…ements (#3214) Co-authored-by: sobolevn <[email protected]>
- Loading branch information
1 parent
a47422d
commit 70b018e
Showing
15 changed files
with
292 additions
and
18 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
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
90 changes: 90 additions & 0 deletions
90
tests/test_visitors/test_ast/test_complexity/test_pm/test_match_subjects.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,90 @@ | ||
import pytest | ||
|
||
from wemake_python_styleguide.violations.complexity import ( | ||
TooManyMatchSubjectsViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.complexity.pm import ( | ||
MatchSubjectsVisitor, | ||
) | ||
|
||
match_call_expr = """ | ||
match some_call(): | ||
case 1: ... | ||
""" | ||
|
||
match_case_long_tuple = """ | ||
match some_call['a']: | ||
case (a, b, c, d, e, f, g, h, i): ... | ||
""" | ||
|
||
match_subjects8 = """ | ||
match a1, b2, c3, d4, e5, f6, g7, h8: | ||
case 1: ... | ||
""" | ||
|
||
match_subjects7 = """ | ||
match a1, b2, c3, d4, e5, f6, g7: | ||
case 1: ... | ||
""" | ||
|
||
|
||
def test_match_subjects_wrong_count( | ||
assert_errors, | ||
assert_error_text, | ||
parse_ast_tree, | ||
default_options, | ||
): | ||
"""Testing that default settings raise a warning.""" | ||
tree = parse_ast_tree(match_subjects8) | ||
|
||
visitor = MatchSubjectsVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooManyMatchSubjectsViolation]) | ||
assert_error_text(visitor, '8', baseline=default_options.max_match_subjects) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code', | ||
[ | ||
match_subjects7, | ||
match_call_expr, | ||
match_case_long_tuple, | ||
], | ||
) | ||
def test_match_subjects_correct_count( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
): | ||
"""Testing that default settings do not raise a warning.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = MatchSubjectsVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code', | ||
[ | ||
match_subjects8, | ||
match_subjects7, | ||
], | ||
) | ||
def test_match_subjects_configured_count( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
options, | ||
): | ||
"""Testing that settings can reflect the change.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_match_subjects=1) | ||
visitor = MatchSubjectsVisitor(option_values, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooManyMatchSubjectsViolation]) |
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
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
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.