Code Monkey home page Code Monkey logo

spew's Introduction

spew

A tool for generating random, syntactically-correct Python code. Designed for fuzzing and testing of tools that parse Python code.

Designed for Python 3.10 and above, this is for testing the latest syntax.

Supports:

  • Functions
  • For, If, While
  • Async With, For, FunctionDef
  • All constant expressions
  • Match statements
  • Many expression types
  • Decorators
  • Classes

Usage

You can use at the command line:

> python -m spew --depth=4

Caution, depths higher than 5 creating a huge recursive computing load. (A depth of 6 creates a file ~40,000 lines of code.)

Also, you can generate specific nodes, like modules or functions:

import spew.generate as g

context = g.Context()
func = g.generate_function(context) # returns an ast.FunctionDef object

To generate AST objects back into Python code you can use the ast.unparse() function.

The full list of command-line options:

python -m spew --help
usage: __main__.py [-h] [--depth DEPTH] [--width WIDTH] [--log-level LOG_LEVEL] [--output OUTPUT] [--check]

options:
  -h, --help            show this help message and exit
  --depth DEPTH         Maximum depth (nesting) of the module
  --width WIDTH
  --log-level LOG_LEVEL
  --output OUTPUT       Output file. If not specified, the output will be printed to the console.
  --check               Check if the code is valid Python

spew's People

Stargazers

Junkai Chen avatar Zhensu Sun avatar Garth Kidd avatar devdanzin avatar Enrique Soria avatar Jair Henrique avatar Daniel Andrlik avatar Ernesto González avatar Jeff Triplett avatar  avatar Tenvi avatar Artur Barseghyan avatar Adam Johnson avatar Sarah Kaiser avatar Murad Akhundov avatar  avatar Nick Khitrov avatar Alcides Fonseca avatar Max Bernstein avatar Jason avatar

Watchers

Anthony Shaw avatar  avatar

spew's Issues

repeated keyword argument

Hi,

This looks like an interesting tool. Gave it a go and my parser found it generates function calls with repeated keyword arguments. Is that a known limitation or a bug?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.