-
-
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.
* Working module counts * Version 0.0.8 release candidate * Ready to be released * Typo fixed
- Loading branch information
Showing
27 changed files
with
776 additions
and
191 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
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
64 changes: 64 additions & 0 deletions
64
tests/test_visitors/test_complexity/test_counts/test_method_counts.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,64 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.complexity.counts import ( | ||
MethodMembersVisitor, | ||
TooManyMethodsViolation, | ||
) | ||
|
||
module_without_methods = """ | ||
def first(): ... | ||
def second(): ... | ||
""" | ||
|
||
class_with_methods = """ | ||
class First(object): | ||
def method(self): ... | ||
def method2(self): ... | ||
""" | ||
|
||
class_with_class_methods = """ | ||
class First(object): | ||
@classmethod | ||
def method(cls): ... | ||
@classmethod | ||
def method2(cls): ... | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
module_without_methods, | ||
class_with_methods, | ||
class_with_class_methods, | ||
]) | ||
def test_method_counts_normal( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that regular classes and functions work well.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visiter = MethodMembersVisitor(default_options) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
class_with_methods, | ||
class_with_class_methods, | ||
]) | ||
def test_method_counts_violation( | ||
assert_errors, parse_ast_tree, code, options, | ||
): | ||
"""Testing that violations are raised when reaching max value.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_methods=1) | ||
visiter = MethodMembersVisitor(option_values) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [TooManyMethodsViolation]) |
55 changes: 55 additions & 0 deletions
55
tests/test_visitors/test_complexity/test_counts/test_module_counts.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,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.complexity.counts import ( | ||
ModuleMembersVisitor, | ||
TooManyModuleMembersViolation, | ||
) | ||
|
||
module_with_function_and_class = """ | ||
def first(): ... | ||
class Second(object): ... | ||
""" | ||
|
||
module_with_methods = """ | ||
class First(object): | ||
def method(self): ... | ||
class Second(object): | ||
def method2(self): ... | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
module_with_function_and_class, | ||
module_with_methods, | ||
]) | ||
def test_module_counts_normal( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that classes and functions in a module work well.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visiter = ModuleMembersVisitor(default_options) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
module_with_function_and_class, | ||
module_with_methods, | ||
]) | ||
def test_module_counts_violation( | ||
assert_errors, parse_ast_tree, code, options, | ||
): | ||
"""Testing that violations are raised when reaching max value.""" | ||
tree = parse_ast_tree(code) | ||
|
||
option_values = options(max_module_members=1) | ||
visiter = ModuleMembersVisitor(option_values) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [TooManyModuleMembersViolation]) |
62 changes: 62 additions & 0 deletions
62
tests/test_visitors/test_complexity/test_function/test_elifs.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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.complexity.function import ( | ||
FunctionComplexityVisitor, | ||
TooManyElifsViolation, | ||
) | ||
|
||
function_with_elifs = """ | ||
def test_module(): | ||
if 1 > 2: | ||
print(1) | ||
elif 2 > 3: | ||
print(2) | ||
elif 3 > 4: | ||
print(3) | ||
else: | ||
print(4) | ||
""" | ||
|
||
function_with_raw_if = """ | ||
def function(): | ||
if 1 == 2: | ||
print(1) | ||
""" | ||
|
||
function_with_if_else = """ | ||
def function(param): | ||
if 1 == 2: | ||
print(1) | ||
else: | ||
print(2) | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
function_with_elifs, | ||
function_with_raw_if, | ||
function_with_if_else, | ||
]) | ||
def test_elif_correct_count( | ||
assert_errors, parse_ast_tree, code, default_options, | ||
): | ||
"""Testing that all `if`/`elif`/`else` stuff is allowed.""" | ||
tree = parse_ast_tree(code) | ||
|
||
visiter = FunctionComplexityVisitor(default_options) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) | ||
|
||
|
||
def test_elif_incorrect_count(assert_errors, parse_ast_tree, options): | ||
"""Testing that incorrect number of `elif` stuff is restricted.""" | ||
tree = parse_ast_tree(function_with_elifs) | ||
|
||
option_values = options(max_elifs=1) | ||
visiter = FunctionComplexityVisitor(option_values) | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [TooManyElifsViolation]) |
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.