How to use the astroid.parse function in astroid

To help you get started, we’ve selected a few astroid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github life4 / deal / tests / test_linter / test_rules.py View on Github external
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
github PyCQA / pylint / tests / unittest_checker_python3.py View on Github external
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)
github life4 / deal / tests / test_linter / test_extractors / test_asserts.py View on Github external
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
github life4 / deal / tests / test_linter / test_extractors / test_common.py View on Github external
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
github life4 / deal / tests / test_linter / test_extractors / test_exceptions_stubs.py View on Github external
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
github pyta-uoft / pyta / tests / test_cfg / test_for_.py View on Github external
def build_cfg(src: str) -> ControlFlowGraph:
    mod = astroid.parse(src)
    t = CFGVisitor()
    mod.accept(t)
    return t.cfgs[mod]
github life4 / deal / tests / test_linter / test_contract.py View on Github external
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
github PyCQA / astroid / astroid / brain / brain_numpy_random_mtrand.py View on Github external
def numpy_random_mtrand_transform():
    return astroid.parse(
        """
    def beta(a, b, size=None): return uninferable
github PyCQA / astroid / astroid / brain / brain_multiprocessing.py View on Github external
def _multiprocessing_managers_transform():
    return astroid.parse(
        """
    import array
github beaker-project / beaker / Misc / pylint_beaker.py View on Github external
def krbV_extend():
    return astroid.parse('''
        class Krb5Error(Exception):