class TestStuff(TestCase):
    @given(st.runner())
    def test_runner_is_self(self, runner):
        assert runner is self

    @given(st.runner(default=3))
    def test_runner_is_self_even_with_default(self, runner):
        assert runner is self
def test_cannot_use_without_a_runner():
    @given(st.runner())
    def f(x):
        pass

    with pytest.raises(InvalidArgument):
        f()
def test_cannot_use_without_a_runner():
    @given(st.runner())
    def f(x):
        pass

    with pytest.raises(InvalidArgument):
        f()
Example #4
0
def valid_slice(draw):
    machine = draw(st.runner())
    result = [
        draw(st.integers(0, max(3, len(machine.model) * 2 - 1))) for _ in range(2)
    ]
    result.sort()
    return slice(*result)
Example #5
0
    def __attrs_post_init__(self):
        arguments = {}
        bundles = []
        for k, v in sorted(self.arguments.items()):
            assert not isinstance(v, BundleReferenceStrategy)
            if isinstance(v, Bundle):
                bundles.append(v)
                consume = isinstance(v, BundleConsumer)
                arguments[k] = BundleReferenceStrategy(v.name, consume)
            else:
                arguments[k] = v
        self.bundles = tuple(bundles)
        self.arguments_strategy = st.fixed_dictionaries(arguments)


self_strategy = st.runner()


class BundleReferenceStrategy(SearchStrategy):
    def __init__(self, name, consume=False):
        self.name = name
        self.consume = consume

    def do_draw(self, data):
        machine = data.draw(self_strategy)
        bundle = machine.bundle(self.name)
        if not bundle:
            data.mark_invalid()
        # Shrink towards the right rather than the left. This makes it easier
        # to delete data generated earlier, as when the error is towards the
        # end there can be a lot of hard to remove padding.
    def __init__(self, settings=None):
        self.program_size = (settings or Settings.default).stateful_step_count

    def do_draw(self, data):
        return StateMachineRunner(data, self.program_size)


@attr.s()
class Rule(object):
    targets = attr.ib()
    function = attr.ib()
    arguments = attr.ib()
    precondition = attr.ib()


self_strategy = runner()


class Bundle(SearchStrategy):

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

    def do_draw(self, data):
        machine = data.draw(self_strategy)
        bundle = machine.bundle(self.name)
        if not bundle:
            data.mark_invalid()
        reference = bundle.pop()
        bundle.insert(integer_range(data, 0, len(bundle)), reference)
        return machine.names_to_values[reference.name]
Example #7
0
 def steps(self):
     return st.runner()
Example #8
0
def test_is_default_in_find():
    t = object()
    assert find(st.runner(t), lambda x: True) == t
Example #9
0
def test_cannot_use_in_find_without_default():
    with pytest.raises(InvalidArgument):
        find(st.runner(), lambda x: True)
Example #10
0
        pass
    with pytest.raises(InvalidArgument):
        f()


def test_cannot_use_in_find_without_default():
    with pytest.raises(InvalidArgument):
        find(st.runner(), lambda x: True)


def test_is_default_in_find():
    t = object()
    assert find(st.runner(t), lambda x: True) == t


@given(st.runner(1))
def test_is_default_without_self(runner):
    assert runner == 1


class TestStuff(TestCase):

    @given(st.runner())
    def test_runner_is_self(self, runner):
        assert runner is self

    @given(st.runner(default=3))
    def test_runner_is_self_even_with_default(self, runner):
        assert runner is self

class RunnerStateMachine(RuleBasedStateMachine):
    @rule(runner=st.runner())
    def step(self, runner):
        assert runner is self
Example #12
0
class StateMachineSearchStrategy(SearchStrategy):

    def __init__(self, settings=None):
        self.program_size = (settings or Settings.default).stateful_step_count

    def do_draw(self, data):
        return StateMachineRunner(data, self.program_size)


Rule = namedtuple(
    u'Rule',
    (u'targets', u'function', u'arguments', u'precondition',
     u'parent_rule')
)

self_strategy = runner()


class Bundle(SearchStrategy):

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

    def do_draw(self, data):
        machine = data.draw(self_strategy)
        bundle = machine.bundle(self.name)
        if not bundle:
            data.mark_invalid()
        reference = bundle.pop()
        bundle.insert(integer_range(data, 0, len(bundle)), reference)
        return machine.names_to_values[reference.name]
Example #13
0
    with pytest.raises(InvalidArgument):
        f()


def test_cannot_use_in_find_without_default():
    with pytest.raises(InvalidArgument):
        find(st.runner(), lambda x: True)


def test_is_default_in_find():
    t = object()
    assert find(st.runner(default=t), lambda x: True) == t


@given(st.runner(default=1))
def test_is_default_without_self(runner):
    assert runner == 1


class TestStuff(TestCase):
    @given(st.runner())
    def test_runner_is_self(self, runner):
        assert runner is self

    @given(st.runner(default=3))
    def test_runner_is_self_even_with_default(self, runner):
        assert runner is self


class RunnerStateMachine(RuleBasedStateMachine):
Example #14
0
def valid_index(draw):
    machine = draw(st.runner())
    if not machine.model:
        return draw(st.nothing())
    return draw(st.integers(0, len(machine.model) - 1))
from __future__ import print_function, division, absolute_import
import operator
import functools

import hypothesis
import hypothesis.stateful
import hypothesis.strategies as st
from nose.tools import assert_equal
from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest

import redis
import fakeredis


self_strategy = st.runner()


@st.composite
def sample_attr(draw, name):
    """Strategy for sampling a specific attribute from a state machine"""
    machine = draw(self_strategy)
    values = getattr(machine, name)
    position = draw(st.integers(min_value=0, max_value=len(values) - 1))
    return values[position]


keys = sample_attr('keys')
fields = sample_attr('fields')
values = sample_attr('values')
scores = sample_attr('scores')