Esempio n. 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()))
Esempio n. 2
0
 def __init__(self,
              search_strategies=None,
              starting_size=1.0,
              warming_rate=0.5,
              cooling_rate=0.1,
              runs_to_explore_flags=3,
              min_satisfying_examples=5,
              max_size=512,
              max_failed_runs=10):
     self.search_strategies = search_strategies or SearchStrategies()
     self.min_satisfying_examples = min_satisfying_examples
     self.starting_size = starting_size
     self.warming_rate = warming_rate
     self.cooling_rate = cooling_rate
     self.max_size = max_size
     self.max_failed_runs = max_failed_runs
     self.runs_to_explore_flags = runs_to_explore_flags
Esempio n. 3
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()))
Esempio n. 4
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)
Esempio n. 5
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
)