-
-
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.
Changes: 1. Forbids old-style classes, closes #35 2. Forbids `staticmethod`, closes #38 3. Forbids `__del__` magic method, closes #44 4. Forbids `async` and `await` variable names, closes #49 5. Forbids `__future__` import, closes #48
- Loading branch information
Showing
16 changed files
with
434 additions
and
144 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
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,39 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.visitors.wrong_class import ( | ||
RequiredBaseClassViolation, | ||
WrongClassVisitor, | ||
) | ||
|
||
|
||
def test_wrong_base_class(assert_errors, parse_ast_tree): | ||
"""Testing that not using explicit base class with forbiden.""" | ||
tree = parse_ast_tree(""" | ||
class WithoutBase: ... | ||
""") | ||
|
||
visiter = WrongClassVisitor() | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [RequiredBaseClassViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('base', [ | ||
'object', | ||
'dict', | ||
'CustomClass', | ||
'Multiple, Classes, Mixins', | ||
'Custom, keyword=1', | ||
]) | ||
def test_regular_base_classes(assert_errors, parse_ast_tree, base): | ||
"""Testing that regular base classes work.""" | ||
tree = parse_ast_tree(""" | ||
class Example({0}): ... | ||
""".format(base)) | ||
|
||
visiter = WrongClassVisitor() | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) |
41 changes: 41 additions & 0 deletions
41
tests/test_visitors/test_wrong_class/test_magic_methods.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,41 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.constants import BAD_MAGIC_METHODS | ||
from wemake_python_styleguide.visitors.wrong_class import ( | ||
BadMagicMethodViolation, | ||
WrongClassVisitor, | ||
) | ||
|
||
magic_method = """ | ||
class Example(object): | ||
def {0}(): ... | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('method', BAD_MAGIC_METHODS) | ||
def test_wrong_magic_used(assert_errors, parse_ast_tree, method): | ||
"""Testing that some magic methods are restricted.""" | ||
tree = parse_ast_tree(magic_method.format(method)) | ||
|
||
visiter = WrongClassVisitor() | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, [BadMagicMethodViolation]) | ||
|
||
|
||
@pytest.mark.parametrize('method', [ | ||
'__add__', | ||
'__init__', | ||
'next', | ||
'regular', | ||
]) | ||
def test_regular_method_used(assert_errors, parse_ast_tree, method): | ||
"""Testing that other methods are working fine.""" | ||
tree = parse_ast_tree(magic_method.format(method)) | ||
|
||
visiter = WrongClassVisitor() | ||
visiter.visit(tree) | ||
|
||
assert_errors(visiter, []) |
Oops, something went wrong.