-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
19 changed files
with
334 additions
and
53 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
125 changes: 125 additions & 0 deletions
125
...test_ast/test_complexity/test_annotation_complexity/test_annotation_complexity_nesting.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,125 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.complexity import ( | ||
TooComplexAnnotationViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.complexity.annotations import ( | ||
AnnotationComplexityVisitor, | ||
) | ||
|
||
annassign_template = 'some: {0}' | ||
|
||
function_arg_template = """ | ||
def some(arg: {0}): | ||
... | ||
""" | ||
|
||
function_return_template = """ | ||
def some(arg) -> {0}: | ||
... | ||
""" | ||
|
||
class_field_template = """ | ||
class Test(object): | ||
some: {0} | ||
other = 1 | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('template', [ | ||
annassign_template, | ||
function_arg_template, | ||
function_return_template, | ||
class_field_template, | ||
]) | ||
@pytest.mark.parametrize('code', [ | ||
'int', | ||
'List[int]', | ||
'List["MyType"]', | ||
'"List[MyType]"', | ||
'Dict[int, str]', | ||
'Callable[[str, int], int]', | ||
'List[List[int]]', | ||
]) | ||
def test_correct_annotations( | ||
assert_errors, | ||
parse_ast_tree, | ||
template, | ||
code, | ||
mode, | ||
default_options, | ||
): | ||
"""Testing that expressions with correct call chain length work well.""" | ||
tree = parse_ast_tree(mode(template.format(code))) | ||
|
||
visitor = AnnotationComplexityVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize('template', [ | ||
annassign_template, | ||
function_arg_template, | ||
function_return_template, | ||
class_field_template, | ||
]) | ||
@pytest.mark.parametrize('code', [ | ||
'List[List[List[int]]]', | ||
'"List[List[List[int]]]"', | ||
'Callable[[], "List[List[str]]"]', | ||
'Callable[[List["List[str]"]], str]', | ||
'Dict[int, Tuple[List[List[str]], ...]]', | ||
'"Dict[int, Tuple[List[List[str]], ...]]"', | ||
'Dict[int, "Tuple[List[List[str]], ...]"]', | ||
'Dict[int, Tuple["List[List[str]]", ...]]', | ||
'Dict[int, Tuple[List["List[str]"], ...]]', | ||
]) | ||
def test_complex_annotations( | ||
assert_errors, | ||
parse_ast_tree, | ||
template, | ||
code, | ||
mode, | ||
default_options, | ||
): | ||
"""Testing that expressions with correct call chain length work well.""" | ||
tree = parse_ast_tree(mode(template.format(code))) | ||
|
||
visitor = AnnotationComplexityVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooComplexAnnotationViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('template', [ | ||
annassign_template, | ||
function_arg_template, | ||
function_return_template, | ||
class_field_template, | ||
]) | ||
@pytest.mark.parametrize('code', [ | ||
'List[List[int]]', | ||
'"List[List[int]]"', | ||
'List["List[int]"]', | ||
]) | ||
def test_complex_annotations_config( | ||
assert_errors, | ||
parse_ast_tree, | ||
template, | ||
code, | ||
mode, | ||
options, | ||
): | ||
"""Testing that expressions with correct call chain length work well.""" | ||
tree = parse_ast_tree(mode(template.format(code))) | ||
|
||
option_values = options(max_annotation_complexity=2) | ||
visitor = AnnotationComplexityVisitor(option_values, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooComplexAnnotationViolation]) |
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.