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=[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.

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

Uploaded Source

File details

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

File metadata

  • Download URL: astcheck-0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for astcheck-0.2.tar.gz
Algorithm Hash digest
SHA256 622f72672f84070842c05fd68d731ac9c1db241fb635f1c657871174d841b5fe
MD5 b2184948a8205cb7f751778068192878
BLAKE2b-256 25383436ce53e3ef6f141b679e4360da362e6535eaebd89608260e23ef2110d1

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