-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
108 additions
and
7 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
58 changes: 58 additions & 0 deletions
58
tests/test_visitors/test_ast/test_keywords/test_raise/test_system_error_violation.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,58 @@ | ||
import pytest | ||
|
||
from wemake_python_styleguide.violations.consistency import ( | ||
RaiseSystemErrorViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.keywords import WrongRaiseVisitor | ||
|
||
template = 'raise {0}' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code', | ||
[ | ||
'SystemError', | ||
'SystemError()', | ||
'SystemError(0)', | ||
'SystemError(code)', | ||
], | ||
) | ||
def test_raise_system_error( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
): | ||
"""Testing `raise SystemError` is restricted.""" | ||
tree = parse_ast_tree(template.format(code)) | ||
|
||
visitor = WrongRaiseVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [RaiseSystemErrorViolation]) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'code', | ||
[ | ||
'NotImplementedError', | ||
'NotImplementedError()', | ||
'CustomSystemError', | ||
'CustomSystemError()', | ||
'custom.SystemError', | ||
'custom.SystemError()', | ||
], | ||
) | ||
def test_raise_good_errors( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
): | ||
"""Testing that other exceptions are allowed.""" | ||
tree = parse_ast_tree(template.format(code)) | ||
|
||
visitor = WrongRaiseVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, []) |
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