skip to navigation
skip to content

astcheck 0.2.4

Check Python ASTs against templates

astcheck compares Python Abstract Syntax Trees against a template. This is useful for testing software that automatically generates or modifies Python code.


pip install astcheck

Example use:

import ast, astcheck

template = ast.Module(body=[
    ast.FunctionDef(name='double', args=ast.arguments(args=[astcheck.mkarg('a')])),

sample = """
def double(a):
    return a*2
b = double(a)

astcheck.assert_ast_like(ast.parse(sample), template)

Only the parts specified in the template are checked. In this example, the code inside the function, and the assignment target (b) could be anything.

For more details, see the documentation.

File Type Py Version Uploaded on Size
astcheck-0.2.4-py2.py3-none-any.whl (md5) Python Wheel py2.py3 2015-03-26 3KB