This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Props

Property-based testing for Python à la QuickCheck.

for_all

for_all takes a list of generators (see below) and a property. It then tests the property for arbitrary values of the generators.

Here’s an example testing the commutative and associative properties of ints:

for_all(int, int)(lambda a, b: a + b == b + a)
for_all(int, int)(lambda a, b: a * b == b * a)
for_all(int, int, int)(lambda a, b, c: c * (a + b) == a * c + b * c)

Generators

Note: These are not the same as Python generators. We should rename them. Generaters? Blech.

A generator is a specification of a set of possible Python objects. A generator is either:

  • One of the following built-in types:
    • None, bool, int, float, long, complex, str, tuple, set, list, or dict
  • A class that implements the ArbitraryInterface
  • Or constructed using the generator combinators.

Combinators

  • maybe_a
    • Generates either an arbitrary value of the specified generator or None.
  • maybe_an
    • An alias for maybe_a. Provided for syntactic convenience.
  • one_of
    • Generates an arbitrary value of one of the specified generators.
  • tuple_of
    • Generates a tuple by generating values for each of the specified generators.
  • set_of
    • Generates a homogeneous set of the specified generator. You can generate non-homogeneous sets using set.
  • list_of
    • Generates a homogeneous list of the specified generator. You can generate non-homogeneous lists using list.
  • dict_of
    • Generates a homogeneous dict of the specified generators using kwargs. You can generate non-homogeneous dicts using dict.

arbitrary

arbitrary takes a generator and returns a single instance of the generator.

ArbitraryInterface

We provide a mixin with one classmethod, arbitrary, which raises NotImplementedError. To implement generators for your own classes, please inherit from ArbitraryInterface and provide an implementation for arbitrary.

Here’s an example implementation of a Binary Tree class:

class BinaryTree(ArbitraryInterface):
    ...
    @classmethod
    def arbitrary(cls):
        return arbitrary(one_of(Leaf, Node))

class Leaf(BinaryTree):
    ...
    @classmethod
    def arbitrary(cls):
        return cls(...)  # an instance of Leaf.

class Node(BinaryTree):
    ...
    @classmethod
    def arbitrary(cls):
        return cls(
            ...
            # This is equivalent:
            arbitrary(BinaryTree),
            # to this:
            BinaryTree.arbitrary()
        )  # an instance of Node with two subtrees.

AbstractTestArbitraryInterface

We also provide an AbstractTestArbitraryInterface with you can mixin to your test cases for each class that implements ArbitraryInterface to ensure the arbitrary method is implemented:

class TestBinaryTree(AbstractTestArbitraryInterface,
                     TestCase):
    def setUp(self):
        self.obj = BinaryTree

To Do

Release History

Release History

0.0.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
props-0.0.2.tar.gz (4.5 kB) Copy SHA256 Checksum SHA256 Source Feb 14, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting