Generation
Given a predicate, py-predicate is able to generate sample data that satisfy that predicate:
NOTE: this feature was introduced in version 0.4 and is not complete yet.
generate_true
This function returns an (potentially infinite, and potentially empty) iterable of values that satisfy the given predicate. Use take from More Itertools to limit the number of return values.
from predicate import generate_true, is_int_p
from more_itertools import take
take(5, generate_true(is_int_p))
In this example we generate 5 values, that will result in True for this predicate.
generate_false
This function returns an (potentially infinite, and potentially empty) iterable of values that don’t satisfy the given predicate.
from predicate import generate_false, is_int_p
from more_itertools import take
take(5, generate_false(is_int_p))
In this example we generate 5 values, that will result in False for this predicate. Note that these values can be anything (strings, floats, dicts, etc.)