Skip to main content

A stochastic Design by Contract utility

Project description

https://travis-ci.org/mhallin/hesitate-py.svg?branch=master

Like assert, but less… assertive.


Are you skipping on writing your assert statements because of performance reasons? Skip no more! Hesitate will, through probabilistic means, make your Design by Contract-assertions faster!

How?

By not executing them.

Yeah.

Hesitate will measure the execution time on every assert statement you write, and execute the slow ones less frequently than the fast ones. You decide on what you think is a reasonable amount of time per assertion, and Hesitate will control how often your assertions run in order to match that.

For assertions with unknown timings, it will use a user configurable initial probability to ensure that a newly started system isn’t flooded by slow assertions.

It looks like this:

# worker.py

def do_work(data):
    assert data_is_valid(data)  # Super slow!

    return work_work(data)


# main.py

import hesitate
hesitate.attach_hook()

import worker
worker.do_work(invalid_data)  # Might not raise AssertionError! Who knows?

Hesitate works with an AST rewriter influenced to py.test. It hooks on to Python’s module loader where it intercepts and rewrites code on the fly as it is loaded.

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

hesitate-0.0.1.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

hesitate-0.0.1-py2.py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 2 Python 3

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