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
11 changed files
with
211 additions
and
29 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 |
---|---|---|
|
@@ -208,6 +208,7 @@ | |
'WPS524': 1, | ||
'WPS525': 2, | ||
'WPS526': 1, | ||
'WPS527': 1, | ||
|
||
'WPS600': 1, | ||
'WPS601': 1, | ||
|
90 changes: 90 additions & 0 deletions
90
tests/test_visitors/test_ast/test_statements/test_not_tuple_argument.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 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.constants import TUPLE_ARGUMENTS_METHODS | ||
from wemake_python_styleguide.violations.refactoring import ( | ||
NotATupleArgumentViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.statements import ( | ||
WrongMethodArgumentsVisitor, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'a = {0}(())', | ||
'a = {0}((1,))', | ||
'a = {0}((1, 2, 3))', | ||
'a = {0}((1,), b)', | ||
'a = {0}((x for x in some))', | ||
'a = {0}((x for x in some), b)', | ||
]) | ||
@pytest.mark.parametrize('method', [ | ||
*TUPLE_ARGUMENTS_METHODS, | ||
]) | ||
def test_passed( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
method, | ||
default_options, | ||
): | ||
"""Ensures that tuples arguments are passed.""" | ||
tree = parse_ast_tree(code.format(method)) | ||
|
||
visitor = WrongMethodArgumentsVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'a = {0}([])', | ||
'a = {0}({1}1{2})', | ||
'a = {0}({1}1, 2, 3{2})', | ||
'a = {0}({1}1{2}, b)', | ||
'a = {0}({1}1{2}, b, c)', | ||
'a = {0}({1}1{2}, b, {1}2{2})', | ||
'a = {0}({1}x for x in some{2})', | ||
]) | ||
@pytest.mark.parametrize('method', [ | ||
*TUPLE_ARGUMENTS_METHODS, | ||
]) | ||
@pytest.mark.parametrize('braces', ['[]', '{}']) # noqa: P103 | ||
def test_no_passed( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
method, | ||
braces, | ||
default_options, | ||
): | ||
"""Ensures that non-tuples arguments are violated.""" | ||
tree = parse_ast_tree(code.format(method, braces[0], braces[1])) | ||
|
||
visitor = WrongMethodArgumentsVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [NotATupleArgumentViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
'a = {0}_func([1])', | ||
]) | ||
@pytest.mark.parametrize('method', [ | ||
*TUPLE_ARGUMENTS_METHODS, | ||
]) | ||
def test_no_checkable( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
method, | ||
default_options, | ||
): | ||
"""Ensures that non checkable situations are skipped.""" | ||
tree = parse_ast_tree(code.format(method)) | ||
|
||
visitor = WrongMethodArgumentsVisitor(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import ast | ||
from typing import Iterator, Sequence | ||
|
||
|
||
def get_all_args(call: ast.Call) -> Sequence[ast.AST]: | ||
"""Gets all arguments (args and kwargs) from ``ast.Call``.""" | ||
return [ | ||
*call.args, | ||
*[kw.value for kw in call.keywords], | ||
] | ||
|
||
|
||
def get_starred_args(call: ast.Call) -> Iterator[ast.Starred]: | ||
"""Gets ``ast.Starred`` arguments from ``ast.Call``.""" | ||
for argument in call.args: | ||
if isinstance(argument, ast.Starred): | ||
yield argument |
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 was deleted.
Oops, something went wrong.
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