skip to navigation
skip to content

Not Logged In

astcheck 0.1

Check Python ASTs against templates

Latest Version: 0.2.4

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

Installation:

pip install astcheck

Example use:

import ast, astcheck

template = ast.Module(body=[
    ast.FunctionDef(name='double', args=ast.arguments(args=[astcheck.mkarg('a')])),
    ast.Assign(value=ast.Call(func=ast.Name(id='double')))
])

sample = """
def double(a):
    do_things()
    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.1.tar.gz (md5, pgp) Source 2014-03-28 3KB
  • Downloads (All Versions):
  • 18 downloads in the last day
  • 147 downloads in the last week
  • 498 downloads in the last month