-
-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for wrong keyword in starred dict (#803)
* Add check for wrong keyword in starred dict * Fix code style * Add tests and move visitor to best_practices
- Loading branch information
Showing
6 changed files
with
133 additions
and
2 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
68 changes: 68 additions & 0 deletions
68
tests/test_visitors/test_ast/test_statements/test_wrong_named_keyword.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,68 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.best_practices import ( | ||
WrongNamedKeywordViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.statements import ( | ||
WrongNamedKeywordVisitor, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'print(**{"@": "2"})', | ||
'print(**{"2ab": "2"})', | ||
'print(**{"!": "2"})', | ||
'print(**{"&a": "2"})', | ||
'print(**{"()": "2"})', | ||
'print(**{"-b": "2"})', | ||
'print(**{"+1": "2"})', | ||
'print(**{"#FFF": "2"})', | ||
'print(**{"some.value": "2"})', | ||
'print(**{"Username[FIELD]": "2"})', | ||
'print(**{"call()": "2"})', | ||
'print(end="|", **{"2ab": "2"})', | ||
]) | ||
def test_wrong_starred_keyword( | ||
assert_errors, | ||
parse_ast_tree, | ||
default_options, | ||
code, | ||
): | ||
"""Testing that pointless starred expression is detected.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = WrongNamedKeywordVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [WrongNamedKeywordViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'_list = [1, 2]', | ||
'_dict = {"end": " "}', | ||
'print(*_list, **_dict)', | ||
'print(end="1", **{"a": 1})', | ||
'filter(**{User.USERNAME_FIELD: username})', # noqa: P103 | ||
'filter(**{"a2": 1, _: 2})', | ||
'filter(**{"a": 1, b: 2})', | ||
'filter(**{"_a": 1, b: 2})', | ||
'filter(**{"a_": 1, b: 2})', | ||
'filter(**{"a": 1, call(): 2})', | ||
'filter(**{"a": 1, b.method(): 2})', | ||
'filter(**{b["a"]: 2})', | ||
]) | ||
def test_correct_starred_keyword( | ||
assert_errors, | ||
parse_ast_tree, | ||
default_options, | ||
code, | ||
): | ||
"""Testing that pointless starred expression is detected.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visitor = WrongNamedKeywordVisitor(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
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