Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_none_return_statement(self):
python_node = self.get_ast_node(
"""
from twisted.internet import defer
@defer.inlineCallbacks
def func(arg):
return None
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=4,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
"""
from twisted.internet import defer
def func(arg):
if arg:
arg += 5
@defer.inlineCallbacks
def inner_func():
return arg
return
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=10,
col_offset=8,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
def test_non_empty_return_statement(self):
python_node = self.get_ast_node(
"""
from twisted.internet import defer
@defer.inlineCallbacks
def func(arg):
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=4,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
def test_empty(self):
python_node = self.get_ast_node(
"""
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
def test_empty_return_statement(self):
python_node = self.get_ast_node(
"""
from twisted.internet import defer
@defer.inlineCallbacks
def func(arg):
return
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
"""
from twisted.internet import defer
@defer.inlineCallbacks
def func(arg):
if condition:
return
if arg > 10:
return
else:
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=12,
col_offset=8,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
@defer.inlineCallbacks
def func(arg):
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = [] if IS_PYTHON_3_3 else [
dlint.linters.base.Flake8Result(
lineno=6,
col_offset=4,
message=dlint.linters.YieldReturnStatementLinter._error_tmpl
)
]
assert result == expected
def test_not_inlinecallbacks_decorator(self):
python_node = self.get_ast_node(
"""
@other_decorator
def func(arg):
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected
def test_attribute_decorator_with_argument(self):
python_node = self.get_ast_node(
"""
CONST = 5
@module.other_decorator(CONST)
def func(arg):
return arg
"""
)
linter = dlint.linters.YieldReturnStatementLinter()
linter.visit(python_node)
result = linter.get_results()
expected = []
assert result == expected