forked from wemake-services/wemake-python-styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test: Created new tests for issue 3. Issue #15 * Test: Modified WPS235 in test_noqa.py. Issue #15 Co-authored-by: iZafiro <60047972+iZafiro@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
69 additions
and
138 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
68 changes: 68 additions & 0 deletions
68
tests/test_visitors/test_ast/test_complexity/test_function/test_raises.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.visitors.ast.complexity.function import ( | ||
FunctionComplexityVisitor, | ||
TooManyRaisesViolation, | ||
) | ||
|
||
function_without_raises = 'def function(): ...' | ||
|
||
function_with_raises = """ | ||
def function(): | ||
if 1 > 2: | ||
raise error1 | ||
raise error2 | ||
""" | ||
|
||
function_with_nested_function_and_raises = """ | ||
def function(): # has two raises | ||
def factory(): # has one raise | ||
raise error3 | ||
raise error4 | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_without_raises, | ||
function_with_raises, | ||
function_with_nested_function_and_raises, | ||
]) | ||
def test_raises_correct_count( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
mode, | ||
): | ||
"""Testing that raises counted correctly.""" | ||
tree = parse_ast_tree(mode(code)) | ||
|
||
visitor = FunctionComplexityVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_with_raises, | ||
function_with_nested_function_and_raises, | ||
]) | ||
def test_raises_wrong_count( | ||
assert_errors, | ||
assert_error_text, | ||
parse_ast_tree, | ||
options, | ||
code, | ||
mode, | ||
): | ||
"""Testing that many raises raises a warning.""" | ||
tree = parse_ast_tree(mode(code)) | ||
|
||
option_values = options(max_raises=1) | ||
visitor = FunctionComplexityVisitor(option_values, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [TooManyRaisesViolation]) | ||
assert_error_text(visitor, '2', option_values.max_raises) |
137 changes: 0 additions & 137 deletions
137
tests/test_visitors/test_ast/test_complexity/test_function/test_raises_count.py
This file was deleted.
Oops, something went wrong.