-
-
Notifications
You must be signed in to change notification settings - Fork 391
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
16 changed files
with
141 additions
and
127 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
tests/test_visitors/test_complexity/test_function/test_expressions.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,48 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.complexity.function import ( | ||
FunctionComplexityVisitor, | ||
TooManyExpressionsViolation, | ||
) | ||
|
||
function_without_expressions = """ | ||
def function(): ... | ||
""" | ||
|
||
function_with_expressions = """ | ||
def function(): | ||
print(12) | ||
print(12 / 1) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_without_expressions, | ||
function_with_expressions, | ||
]) | ||
def test_expressions_correct_count( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that expressions counted correctly.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visiter = FunctionComplexityVisitor(default_options) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_with_expressions, | ||
]) | ||
def test_expressions_wrong_count(assert_errors, parse_ast_tree, options, code): | ||
"""Testing that many expressions raises a warning.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_expressions=1) | ||
visiter = FunctionComplexityVisitor(option_values) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [TooManyExpressionsViolation]) |
49 changes: 49 additions & 0 deletions
49
tests/test_visitors/test_complexity/test_function/test_returns.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,49 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.complexity.function import ( | ||
FunctionComplexityVisitor, | ||
TooManyReturnsViolation, | ||
) | ||
|
||
function_without_returns = """ | ||
def function(): ... | ||
""" | ||
|
||
function_with_returns = """ | ||
def function(): | ||
if 1 > 2: | ||
return 1 | ||
return 0 | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_without_returns, | ||
function_with_returns, | ||
]) | ||
def test_returns_correct_count( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that returns counted correctly.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visiter = FunctionComplexityVisitor(default_options) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_with_returns, | ||
]) | ||
def test_returns_wrong_count(assert_errors, parse_ast_tree, options, code): | ||
"""Testing that many returns raises a warning.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_returns=1) | ||
visiter = FunctionComplexityVisitor(option_values) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [TooManyReturnsViolation]) |
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