-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#271] Restricted variable names with more than one consecutive under…
…score (#277) * restricted variable names with more than one concecutive underscore * changelog update * put pyproject.lock back to project * fixed naming and added missed blank lines * fixing errors bringed with merge conflict resolving
- Loading branch information
Showing
5 changed files
with
187 additions
and
4 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
72 changes: 72 additions & 0 deletions
72
tests/test_visitors/test_ast/test_naming/test_consecutive_underscore_in_variable_name.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,72 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
from wemake_python_styleguide.violations.naming import ( | ||
ConsecutiveUnderscoresInNameViolation, | ||
) | ||
from wemake_python_styleguide.visitors.ast.naming import WrongNameVisitor | ||
|
||
variable_test = """ | ||
{0} = 'test' | ||
""" | ||
|
||
underscore_variable_test1 = """ | ||
_{0} = 'test' | ||
""" | ||
|
||
underscore_variable_test2 = """ | ||
{0}_ = 'test' | ||
""" | ||
|
||
for_variable_test = """ | ||
for {0} in []: | ||
print() | ||
""" | ||
|
||
async_for_variable_test = """ | ||
async def container(): | ||
async for {0} in []: | ||
print() | ||
""" | ||
|
||
with_variable_test = """ | ||
with open('test.py') as {0}: | ||
raise ValueError() | ||
""" | ||
|
||
async_with_variable_test = """ | ||
async def container(): | ||
async with open('test.py') as {0}: | ||
raise ValueError() | ||
""" | ||
|
||
exception_test = """ | ||
try: | ||
1 / 0 | ||
except Exception as {0}: | ||
raise | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize('code', [ | ||
variable_test, | ||
for_variable_test, | ||
async_for_variable_test, | ||
with_variable_test, | ||
async_with_variable_test, | ||
exception_test, | ||
]) | ||
def test_consecutive_underscores_in_variable_name( | ||
assert_errors, | ||
parse_ast_tree, | ||
code, | ||
default_options, | ||
): | ||
"""Testing that variable can not have private names.""" | ||
tree = parse_ast_tree(code.format('some__value')) | ||
|
||
visitor = WrongNameVisitor(default_options, tree=tree) | ||
visitor.run() | ||
|
||
assert_errors(visitor, [ConsecutiveUnderscoresInNameViolation]) |
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