Skip to main content

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.3.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

astcheck-0.3.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file astcheck-0.3.0.tar.gz.

File metadata

  • Download URL: astcheck-0.3.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for astcheck-0.3.0.tar.gz
Algorithm Hash digest
SHA256 360d998cf9c67baf4bea1729c161a292c4bbec272a0a25f35e793dc6a59758c0
MD5 bfec9d0b7f1b2b2ef41f569f8d762925
BLAKE2b-256 ef297a7ab173ddcd7e5f90e59adc85f4e3641cfd85889e16817242f8548132f6

See more details on using hashes here.

File details

Details for the file astcheck-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: astcheck-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for astcheck-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d692cb6c2f4fb23ff0e2fa8be77ac5155c36d3e05c465a64a3de3851767bdda0
MD5 19c8f7286fae700444288409bc7ecfeb
BLAKE2b-256 d531303e50a1f8fdf01c86cdc2e3cf11e377bb21f09493ee3f137bc0815ef492

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page