Skip to content

Commit

Permalink
test no returns
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed May 4, 2020
1 parent a0cb6bd commit 27992b8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deal/linter/_rules.py
Expand Up @@ -163,7 +163,7 @@ def _check(self, func: Func, stubs: StubsManager = None) -> Iterator[Error]:
yield Error(
code=self.code,
text=self.message,
value='return',
value='no return',
row=func.line,
col=func.col,
)
Expand Down
20 changes: 19 additions & 1 deletion tests/test_linter/test_extractors/test_returns.py
Expand Up @@ -6,7 +6,7 @@
import pytest

# project
from deal.linter._extractors import get_returns
from deal.linter._extractors import get_returns, has_returns


@pytest.mark.parametrize('text, expected', [
Expand Down Expand Up @@ -57,3 +57,21 @@ def test_get_returns_inference(text, expected):
print(tree.repr_tree())
returns = tuple(r.value for r in get_returns(body=tree.body))
assert returns == expected


@pytest.mark.parametrize('text, expected', [
('return', True),
('return 1', True),
('if b:\n return 1', True),
('yield 1', True),
('if b:\n yield 1', True),
('1 + 2', False),
])
def test_has_returns(text, expected):
tree = ast.parse(text)
print(ast.dump(tree))
assert has_returns(body=tree.body) is expected

tree = astroid.parse(text)
print(tree.repr_tree())
assert has_returns(body=tree.body) is expected
17 changes: 17 additions & 0 deletions tests/test_linter/test_rules.py
Expand Up @@ -158,6 +158,23 @@ def test(a):
assert actual == expected


def test_check_pure_no_returns():
checker = CheckPure()
text = """
@deal.pure
def test(a):
a + 3
"""
text = dedent(text).strip()
funcs1 = Func.from_ast(ast.parse(text))
funcs2 = Func.from_astroid(astroid.parse(text))
for func in (funcs1[0], funcs2[0]):
actual = [tuple(err) for err in checker(func)]
assert len(actual) == 1
expected = 'DEAL014 pure contract error (no return)'
assert actual[0][2] == expected


def test_check_asserts():
checker = CheckAsserts()
text = """
Expand Down

0 comments on commit 27992b8

Please sign in to comment.