Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takluyver/astcheck
Check Python ASTs against templates
https://github.com/takluyver/astcheck
Last synced: about 2 months ago
JSON representation
Check Python ASTs against templates
- Host: GitHub
- URL: https://github.com/takluyver/astcheck
- Owner: takluyver
- License: mit
- Created: 2014-03-27T19:27:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-01-29T12:02:30.000Z (11 months ago)
- Last Synced: 2024-10-11T19:19:07.503Z (3 months ago)
- Language: Python
- Homepage: http://astcheck.readthedocs.org/en/latest/
- Size: 48.8 KB
- Stars: 17
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
astcheck
========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:
.. code:: python
import ast, astcheck
template = ast.Module(body=[
ast.FunctionDef(name='double', args=ast.arguments(args=[ast.arg(arg='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 `_.