Check Python ASTs against templates
Project Description
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.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size & hash SHA256 hash help | File type | Python version | Upload date |
---|---|---|---|
astcheck-0.2.5-py2.py3-none-any.whl (10.4 kB) Copy SHA256 hash SHA256 | Wheel | py2.py3 | Apr 18, 2018 |
astcheck-0.2.5.tar.gz (12.2 kB) Copy SHA256 hash SHA256 | Source | None | Apr 18, 2018 |