-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_exception_on_invalid_code.py
More file actions
33 lines (22 loc) · 939 Bytes
/
test_exception_on_invalid_code.py
File metadata and controls
33 lines (22 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Checks for exceptions raised on invalid code."""
import ast
import libcst as cst
import pytest
from flake8_async.visitors.helpers import iter_guaranteed_once, iter_guaranteed_once_cst
def _raises_on_code_cst(source: str):
expression = cst.parse_expression(source)
with pytest.raises(RuntimeError, match="Invalid literal values"):
iter_guaranteed_once_cst(expression)
def test_iter_guaranteed_once_cst():
_raises_on_code_cst("range(1, 10, 0)")
_raises_on_code_cst("range(5, 2, 3, 4)")
def _raises_on_code_ast(source: str):
expression = ast.parse(source).body[0]
assert isinstance(expression, ast.Expr)
call = expression.value
assert isinstance(call, ast.Call)
with pytest.raises(RuntimeError, match="Invalid literal values"):
iter_guaranteed_once(call)
def test_iter_guaranteed_once():
_raises_on_code_ast("range(1, 10, 0)")
_raises_on_code_ast("range(5, 2, 3, 4)")