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_check_raises_without_allowed():
checker = CheckRaises()
text = """
@deal.raises()
def test(a):
raise ValueError
"""
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)]
expected = [(3, 10, 'DEAL021 raises contract error (ValueError)')]
assert actual == expected
def as_iterable_in_listcomp_test(self, fxn):
code = "x = [x for x in {}(None, [1])]".format(fxn)
module = astroid.parse(code)
with self.assertNoMessages():
self.walk(module)
def test_get_asserts_simple(text, expected):
tree = astroid.parse(text)
print(tree.repr_tree())
returns = tuple(r.value for r in get_asserts(body=tree.body))
assert returns == expected
tree = ast.parse(text)
print(ast.dump(tree))
returns = tuple(r.value for r in get_asserts(body=tree.body))
assert returns == expected
def test_infer(text, expected):
tree = astroid.parse(text)
print(tree.repr_tree())
expr = tree.body[-1].value
actual = infer(expr=expr)
assert [get_full_name(e) for e in actual] == expected
def test_get_module():
tree = astroid.parse('def f(): pass')
print(tree.repr_tree())
assert _get_module(expr=tree) is tree
assert _get_module(expr=tree.body[0]) is tree
tree.body[0].parent = None
assert _get_module(expr=tree.body[0]) is None
def build_cfg(src: str) -> ControlFlowGraph:
mod = astroid.parse(src)
t = CFGVisitor()
mod.accept(t)
return t.cfgs[mod]
def test_simplified_signature():
text = """
import deal
@deal.post(lambda _: _.a > _.b)
def f(a, b):
return a + b
"""
text = dedent(text).strip()
funcs1 = Func.from_ast(ast.parse(text))
assert len(funcs1) == 1
funcs2 = Func.from_astroid(astroid.parse(text))
assert len(funcs2) == 1
for func in (funcs1[0], funcs2[0]):
assert len(func.contracts) == 1
c = func.contracts[0]
assert c.run(3, 2) is True
assert c.run(2, 3) is False
def numpy_random_mtrand_transform():
return astroid.parse(
"""
def beta(a, b, size=None): return uninferable
def _multiprocessing_managers_transform():
return astroid.parse(
"""
import array
def krbV_extend():
return astroid.parse('''
class Krb5Error(Exception):