GithubHelp home page GithubHelp logo

msoedov / quick.py Goto Github PK

View Code? Open in Web Editor NEW
16.0 3.0 3.0 58 KB

Property-based testing library for Python

Makefile 1.77% Python 98.23%
property-based-testing python quickcheck type-annotations

quick.py's Introduction

quick.py

Build Status PyPI Supported versions Code Issues Join the chat at https://gitter.im/msoedov/quick.py

Quick.py is a property-based testing library for Python inspired by the Haskell library QuickCheck. The core idea of QuickCheck is that instead of enumerating expected input and output for unit tests, you write properties about your function that should hold true for all inputs. This lets you write concise, powerful tests.

Installation

pip install quick.py

Examples

Basic example:

# example.py
from quick.features import QuickCheck

qc = QuickCheck(max_count=100)


@qc.forall('Associative property of addition for integers')
def prop(x: int, y: int):
    return (x + y) == (y + x)


TestAddtion = qc.as_testcase()
>>> nosetests example.py
....................................................................................................
----------------------------------------------------------------------
Ran 100 tests in 0.061s

OK

Custom generators:

# example.py
from quick.features import QuickCheck
from quick.generators import number
from quick.arbitrary import A

qc = QuickCheck(max_count=100)


def non_empty_list(el: number, ls: [number]):
    """
    Generator which always returns non empty list
    """
    ls.append(el)
    return ls


@qc.forall('The first element of a sorted list should be always lesser or eq than the last')
def prop(x: non_empty_list):
    sorted_x = sorted(x)
    first = sorted_x[0]
    last = sorted_x[-1]
    return first <= last


TestSort = qc.as_testcase()
>>> nosetests example.py
....................................................................................................
----------------------------------------------------------------------
Ran 100 tests in 0.070s

OK

Features

  • Integration with unittests library
  • Custom generators
  • Simplification/Shrinking of failure input (in progress)

Controlled Randomness

def working_time(a: A):
    day = a.choose_one('Monday', 'Tuesday', 'Wednesday', 'Thursday')
    hour = a.choose(8, 17)
    return {'day': day, 'hour': hour}

Custom object generators

class User(object):

    def __init__(self, name, age):
        self.name = name
        self.age = age


def user_gen(name: str, a: A):
    age = a.choose(18, 100)
    return User(name, age)


@forall('Valid users')
def prop(user: user_gen):
    return ...

Shrinking

TBD, It's a trial implementation, and has limited functionalities yet.

Python 2 support?

Oups, sorry

Getting Help

For feature requests and bug reports submit an issue to the GitHub issue tracker for quick.py.

quick.py's People

Contributors

gitter-badger avatar msoedov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

quick.py's Issues

Fix skipped tests

Currently a bunch of tests are skipped due small breaking changes

======================================================================
1) SKIP: test_generate_map (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================
2) SKIP: test_generate_map_complex (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================
3) SKIP: test_generate_map_nested_gen (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================
4) SKIP: test_generate_set (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================
5) SKIP: test_generate_tuple (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================
6) SKIP: test_unknown (tests.test_core.TestGenerate)
----------------------------------------------------------------------
   No Traceback
   Exception: changed api
======================================================================


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.