Пример #1
0
def test_can_falsify_types_without_default_productions():
    strategies = SearchStrategies()
    strategies.define_specification_for(Bar, BarStrategy)

    with pytest.raises(MissingSpecification):
        SearchStrategies.default().strategy(Bar)

    verifier = Verifier(search_strategies = strategies)
    assert verifier.falsify(lambda x : False, Bar,)[0] == Bar()
    assert verifier.falsify(lambda x : x.size() < 3, Bar)[0] == Bar(Bar(Bar()))
Пример #2
0
def test_can_falsify_types_without_default_productions():
    strategies = SearchStrategies()
    strategies.define_specification_for(Bar, BarStrategy)

    with pytest.raises(MissingSpecification):
        SearchStrategies.default().strategy(Bar)

    verifier = Verifier(search_strategies=strategies)
    assert verifier.falsify(
        lambda x: False,
        Bar,
    )[0] == Bar()
    assert verifier.falsify(lambda x: x.size() < 3, Bar)[0] == Bar(Bar(Bar()))
Пример #3
0

class StatefulStrategy(MappedSearchStrategy):
    def __init__(self, strategies, descriptor, **kwargs):
        SearchStrategy.__init__(self, strategies, descriptor, **kwargs)
        step_strategies = [
            StepStrategy(strategies, s) for s in descriptor.test_steps()
        ]
        child_mapper = strategies.new_child_mapper()
        child_mapper.define_specification_for(
            Step, lambda sgs, _: sgs.strategy(one_of(step_strategies)))
        self.mapped_strategy = child_mapper.strategy([Step])

    def pack(self, x):
        return TestRun(self.descriptor, x)

    def unpack(self, x):
        return x.steps

    def simplify(self, x):
        pruned = x.prune()
        if pruned:
            yield pruned

        for y in MappedSearchStrategy.simplify(self, x):
            yield y


SearchStrategies.default().define_specification_for_classes(
    StatefulStrategy, subclasses_of=StatefulTest)
Пример #4
0
        SearchStrategy.__init__(self, strategies, descriptor, **kwargs)
        step_strategies = [
            StepStrategy(strategies, s)
            for s in descriptor.test_steps()
        ]
        child_mapper = strategies.new_child_mapper()
        child_mapper.define_specification_for(
            Step,
            lambda sgs, _: sgs.strategy(one_of(step_strategies))
        )
        self.mapped_strategy = child_mapper.strategy([Step])

    def pack(self, x):
        return TestRun(self.descriptor, x)

    def unpack(self, x):
        return x.steps

    def simplify(self, x):
        pruned = x.prune()
        if pruned:
            yield pruned

        for y in MappedSearchStrategy.simplify(self, x):
            yield y

SearchStrategies.default().define_specification_for_classes(
    StatefulStrategy,
    subclasses_of=StatefulTest
)