API Reference

pyquchk Package

Contains main functions and facilities you will need when using pyquchk. They all can be imported with from pyquchk import ..., no need to specify exact modules.

pyquchk.qc_decorator.qc(ntests=100)[source]

Decorator for a test function.

For usage examples see Writing and running tests.

Parameters:ntests – number of tests
pyquchk.checker.for_all(func, _ntests=100, **kwargs)[source]

Test the function func on _ntests tests.

For usage examples see Property checking.

Parameters:
  • _ntests – number of tests
  • kwargs – function arguments specification
Returns:

information about the tests run

Return type:

Result

class pyquchk.checker.Result(verdict, passed, data=None, exception=None, traceback=None)[source]

Represent the result of performed testing (returned by for_all()).

__bool__()[source]

Return passed, used to interprete as a bool value.

__nonzero__()

Return passed, used to interprete as a bool value.

data = None

Data on which the tested function failed (as a dict), or None if passed

exception = None

Exception raised by the function, or ReturnedFalse if function returned False, or None if passed

failed = None

False if passed and True if not (opposite to passed)

passed = None

True if passed and False if not (opposite to failed)

traceback = None

Exception traceback, or None if passed

verdict = None

'OK' if passed and 'FAIL' if not

exception pyquchk.checker.ReturnedFalse(retval)[source]

Automatically raised when the tested function returns a value which evaluates to a bool False.

retval = None

Exact value returned by the function (evaluates to a False bool value)

exception pyquchk.checker.CheckError[source]

Raised when a test which uses qc() decorator fails.

It contains the original test data for which the test has failed, and the exception raised by the tested function. Actually, a CheckError instance is always also an instance of the exception raised by the tested function, so you can except it as usually.

cause = None

Exception raised by the function, or ReturnedFalse if function returned False

test_data = None

Data which caused the function to raise an exception

pyquchk.arbitraries Package

Contains all the built-in Arbitrary instances. They all can be imported with from pyquchk.arbitraries import ..., no need to specify exact modules.

class pyquchk.arbitraries.numbers.bool_[source]

Any bool value (False or True).

class pyquchk.arbitraries.numbers.const(value=None)[source]

Any constant value.

class pyquchk.arbitraries.numbers.elements(*el_list)[source]

Choice from a list of constant values.

pyquchk.arbitraries.numbers.float_

alias of float_fraction

class pyquchk.arbitraries.numbers.float_exp(sig=<pyquchk.arbitraries.numbers.float_uniform object at 0x3916950>, exp=<pyquchk.arbitraries.numbers.int_ object at 0x3916990>, sign=<pyquchk.arbitraries.numbers.elements object at 0x39169d0>)[source]

Float with significand, exponent and sign taken according to the parameters.

class pyquchk.arbitraries.numbers.float_fraction(low=-100, high=100, denom=<pyquchk.arbitraries.numbers.int_ object at 0x3916710>)[source]

Uniformly distributed float from the specified range, representing a fraction with a denominator taken according to denom.

class pyquchk.arbitraries.numbers.float_uniform(low=-100, high=100)[source]

Uniformly distributed float from the specified range.

class pyquchk.arbitraries.numbers.int_(low=-4294967296, high=4294967295)[source]

Uniformly distributed integer from the specified range.

class pyquchk.arbitraries.numbers.oneof(*arbitraries)[source]

Choice (possible weighed) from a list of Arbitraries.

class pyquchk.arbitraries.sequences.list_(length=<pyquchk.arbitraries.numbers.int_ object at 0x3916d10>, elements=<class 'pyquchk.arbitraries.numbers.int_'>)[source]

List with length and elements taken from specified Arbitraries.

arbitrary Module

class pyquchk.arbitraries.arbitrary.Arbitrary[source]
static args_for_sample(*args, **kwargs)[source]
could_generate(x)[source]

Check if x could’ve been generated by self.

You can override this method, but it’s not used now in any way.

gen_serial(amount)[source]

Generate or return a sequence of serial values (finite or infinite amount).

You should override this method.

static get_all()[source]
static get_for(type)[source]

Get default Arbitrary for the specified type.

next_random()[source]

Get next random value.

You should override this method.

classmethod sample()[source]
static set_for(type)[source]
shrink(x)[source]

Get possible shrinkings of x. You can assume here that self.could_generate(x) == True.

You have to override this method if you want shrinking to be available.

class pyquchk.arbitraries.arbitrary.ArbitraryMeta(name, bases, attrs)[source]
arbitrary_cls

alias of Arbitrary

pyquchk.arbitraries.arbitrary.combomethod[source]

utils Module

Contain utility functions and decorators useful when defining custom Arbitrary instances. Usually they haven’t much use otherwise.

pyquchk.arbitraries.utils.roundrobin(iterables)[source]

Yield items from the given iterables in a round-robin fashion.

What it does exactly is better explained with a simple example:

>>> list(roundrobin(['ABC', 'D', 'EF']))
['A', 'D', 'E', 'B', 'F', 'C']
Parameters:iterables – List of finite or infinite iterables.
pyquchk.arbitraries.utils.choice_weighted(elements)[source]

Like random.choice(), but the probability an item is chosen is proportional to its weight.

For convenience, this function is available as random.choice_weighted if you imported utils.

Parameters:elements – list of tuples (item, weight), weight is any numeric value
pyquchk.arbitraries.utils.filter_possible(method)[source]

Decorator, when applied to a generator method (e.g. gen_serial()) filters generated values to keep only those for which could_generate() returns True.

pyquchk.arbitraries.utils.until_possible(method)[source]

Decorator, when applied to a method returning different values each time (e.g. next_random()) runs this method multiple times until a value for which could_generate() returns True is returned, and finally returns this value.

pyquchk.arbitraries.utils.unique(method)[source]

Decorator, when applied to a generator method (e.g. gen_serial(), shrink()) filters generated values to keep only unique values. For the shrink() method the value passed to the method is also considered.

Project Versions

Table Of Contents

Previous topic

Features

This Page