Skip to content

Commit

Permalink
Closes #1866 (#1870)
Browse files Browse the repository at this point in the history
* Closes #1866

* Fixes CI

* Fixes CI

* Fixes CI

* Fixes CI
  • Loading branch information
sobolevn authored Feb 11, 2021
1 parent 5671e97 commit 1f94c39
Show file tree
Hide file tree
Showing 12 changed files with 824 additions and 267 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/noqa/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ def useless_returning_else():


def multiple_return_path():
try: # noqa: WPS419
try: # noqa: WPS419, WPS503
return 1
except Exception:
return 2
Expand Down
2 changes: 1 addition & 1 deletion tests/test_checker/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
'WPS500': 1,
'WPS501': 1,
'WPS502': 2,
'WPS503': 1,
'WPS503': 2,
'WPS504': 1,
'WPS505': 1,
'WPS506': 1,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from wemake_python_styleguide.violations.refactoring import (
SimplifiableReturningIfViolation,
UselessReturningElseViolation,
)
from wemake_python_styleguide.visitors.ast.conditions import IfStatementVisitor

Expand All @@ -15,13 +14,6 @@ def some_function():
return {1}
"""

simple_early_returning_if = """
def some_function():
if some_condition:
return {0}
return {1}
"""

complex_early_returning_if_inside = """
def some_function():
if some_condition:
Expand Down Expand Up @@ -54,7 +46,29 @@ def some_function():
return {0}
"""

simple_early_returning_if = """
def some_function():
if some_condition:
return {0}
return {1}
"""

early_returning_if_else = """
def some_function():
if some_condition:
return {0}
else:
return {1}
"""


@pytest.mark.parametrize('code', [
simple_early_returning_if,
early_returning_if_else,
complex_early_returning_if_inside,
complex_early_returning_if_outside,
])
@pytest.mark.parametrize('comparators', [
('variable', '"test"'),
('12', 'variable.call()'),
Expand All @@ -64,11 +78,12 @@ def some_function():
def test_complex_early_returning_if(
assert_errors,
parse_ast_tree,
code,
comparators,
default_options,
):
"""These early returning ifs can not be simplified."""
tree = parse_ast_tree(simple_early_returning_if.format(*comparators))
tree = parse_ast_tree(code.format(*comparators))

visitor = IfStatementVisitor(
default_options,
Expand Down Expand Up @@ -103,6 +118,10 @@ def test_complex_early_returning_if_inside(
assert_errors(visitor, [])


@pytest.mark.parametrize('code', [
simple_early_returning_if,
early_returning_if_else,
])
@pytest.mark.parametrize('comparators', [
('True', 'False'),
('False', 'True'),
Expand All @@ -111,15 +130,13 @@ def test_simplifiable_early_returning_if(
assert_errors,
parse_ast_tree,
comparators,
code,
default_options,
):
"""These early returning ifs are simplifiable."""
tree = parse_ast_tree(simple_early_returning_if.format(*comparators))
tree = parse_ast_tree(code.format(*comparators))

visitor = IfStatementVisitor(
default_options,
tree=tree,
)
visitor = IfStatementVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [SimplifiableReturningIfViolation])
Expand All @@ -141,7 +158,7 @@ def test_complex_else(
visitor = IfStatementVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [UselessReturningElseViolation])
assert_errors(visitor, [])


@pytest.mark.parametrize('comparators', [
Expand All @@ -160,7 +177,7 @@ def test_not_simplifiable_elif(
visitor = IfStatementVisitor(default_options, tree=tree)
visitor.run()

assert_errors(visitor, [UselessReturningElseViolation])
assert_errors(visitor, [])


@pytest.mark.parametrize('comparators', [
Expand Down
Loading

0 comments on commit 1f94c39

Please sign in to comment.