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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

Details for the file hesitate-0.0.1.tar.gz.

File metadata

  • Download URL: hesitate-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for hesitate-0.0.1.tar.gz
Algorithm Hash digest
SHA256 62a90b179627a59692e6fbd15bfc832be5d43fd982d15690cb0cfff70ba90777
MD5 ea2b0f6e81b51997c8b0a26446c04bcf
BLAKE2b-256 ba360693d91f6b7f5cfb2df162e0f5768d4b157ae99ea0b056808608c983899a

See more details on using hashes here.

File details

Details for the file hesitate-0.0.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for hesitate-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a159dece4cea655c51f6aabf0ff1649ed2f16a54f616ef62bdd6d744b66fd441
MD5 78ad4788bb3edb68b471d338e499e00c
BLAKE2b-256 24a13cf7cb3ed7931ff52078fbbb97bc87b39270779f905617e64918c0f2c2d0

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