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=[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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
astcheck-0.4.0.tar.gz
(13.8 kB
view details)
Built Distribution
File details
Details for the file astcheck-0.4.0.tar.gz
.
File metadata
- Download URL: astcheck-0.4.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e979b7450aff2b9ddc166f0533141d8a3b13ce0dfb923efa76fe9ed7c8747844 |
|
MD5 | b88756a25c02b17a0373b6fc878d0b4f |
|
BLAKE2b-256 | d4477b70dbf934043b983b2dd7cc87e9df8ca562ffcbb0798f9de7fcdb8561ff |
Provenance
File details
Details for the file astcheck-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: astcheck-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b21ed9943cf4f87a5d2092b8550c8314537d6fa43143d21d517c20a64aa7d56 |
|
MD5 | 663b930609a7031685996e57443fadd3 |
|
BLAKE2b-256 | de053ec7e5edcf634bd826bd8463f6a7a3f0fa8202aa21b67809c97e61c49b8c |