Skip to main content

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:

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.

Metadata

Release files for astcheck 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for astcheck 0.4.0
File Size Uploaded
astcheck-0.4.0.tar.gz 13.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for astcheck 0.4.0
File Interpreter ABI Platform
astcheck-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / astcheck-0.4.0.tar.gz

Download URL astcheck-0.4.0.tar.gz
Size 13.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e979b7450aff2b9ddc166f0533141d8a3b13ce0dfb923efa76fe9ed7c8747844
BLAKE2b-256 checksum
How to use checksums
d4477b70dbf934043b983b2dd7cc87e9df8ca562ffcbb0798f9de7fcdb8561ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / astcheck-0.4.0-py3-none-any.whl

Download URL astcheck-0.4.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b21ed9943cf4f87a5d2092b8550c8314537d6fa43143d21d517c20a64aa7d56
BLAKE2b-256 checksum
How to use checksums
de053ec7e5edcf634bd826bd8463f6a7a3f0fa8202aa21b67809c97e61c49b8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page