lisa.fuzz#

Fuzzing API to build random constrained values.

Note

The following example shows a direct use of the Gen monad, but be aware that lisa.wlgen.rta API allows mixing both Gen and RTA DSL into the same coroutine function using lisa.wlgen.rta.task_factory().

Example:

from lisa.platforms.platinfo import PlatformInfo
from lisa.fuzz import GenMonad, Choice, Int, Float, retry_until

# The function must be decorated with GenMonad.do() so that "await" gains
# its special meaning.
@GenMonad.do
async def make_data(duration=None):
    # Draw a value from an iterable.
    period = await Choice([16e-3, 8e-3])
    nr = await Choice(range(1, 4))
    duration = duration or (await Float(1, 2))

    # Arbitrary properties can be enforced. If they are not satisfied, the
    # function will run again until the condition is true.
    await retry_until(0 < nr <= 2)

    return (nr, duration, period)

# seed (or rng) can be fixed for reproducible results
data = make_data(duration=42)(seed=1)
print(data)

Classes

Bool

Draw a random bool.

Choice

Randomly choose one values among xs.

Choices

Randomly choose n values among xs.

Dict

Same as lisa.fuzz.Choices but returns a dictionary.

Float

Draw a random float fitting within the [min_, max_] range.

Gen

GenMonad

Random generator monad inspired by Haskell’s QuickCheck.

Int

Draw a random int fitting within the [min_, max_] range.

Set

Same as lisa.fuzz.Choices but returns a set.

Shuffle

Randomly shuffle the given sequence.

SortedList

Same as lisa.fuzz.Choices but returns a sorted list.

Tuple

Same as lisa.fuzz.Choices but returns a tuple.

Functions

retry_until()

Returns an awaitable that will signify to the lisa.fuzz.Gen monad to retry the computation until cond is True. This is used to enforce arbitrary constraints on generated data.

Exceptions

RetryException

Exception raised to signify to lisa.fuzz.Gen to retry the random draw.