Skip to content

Commit

Permalink
Issue #15 (#23)
Browse files Browse the repository at this point in the history
* 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
adrwes and iZafiro committed Feb 27, 2020
1 parent ac7accb commit 0ee0175
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 138 deletions.
2 changes: 1 addition & 1 deletion tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
'WPS232': 0, # logically unacceptable.
'WPS233': 1,
'WPS234': 1,
'WPS235': 3, # Gwin73 and iZafiro
'WPS235': 1,

'WPS300': 1,
'WPS301': 1,
Expand Down
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)

This file was deleted.

0 comments on commit 0ee0175

Please sign in to comment.