def __init__(self, children): SearchStrategy.__init__(self) children = tuple(children) self.values = [ t for _, t in children ] self.sampler = Sampler([s for s, _ in children])
def __init__(self, function, args, kwargs): SearchStrategy.__init__(self) self.__wrapped_strategy = None self.__representation = None self.function = function self.__args = args self.__kwargs = kwargs
def __init__(self, function, args, kwargs, filters=(), *, force_repr=None): SearchStrategy.__init__(self) self.__wrapped_strategy = None self.__representation = force_repr self.function = function self.__args = args self.__kwargs = kwargs self.__filters = filters
def __init__(self, elements, min_size=0, max_size=float("inf")): SearchStrategy.__init__(self) self.min_size = min_size or 0 self.max_size = max_size if max_size is not None else float("inf") assert 0 <= self.min_size <= self.max_size self.average_size = min( max(self.min_size * 2, self.min_size + 5), 0.5 * (self.min_size + self.max_size), ) self.element_strategy = elements
def __init__(self, lower_bound, upper_bound, width): SearchStrategy.__init__(self) assert isinstance(lower_bound, float) assert isinstance(upper_bound, float) assert 0 <= lower_bound < upper_bound assert math.copysign(1, lower_bound) == 1, "lower bound may not be -0.0" assert width in (16, 32, 64) self.lower_bound = lower_bound self.upper_bound = upper_bound self.width = width
def __init__(self, allow_infinity, allow_nan, width): SearchStrategy.__init__(self) assert isinstance(allow_infinity, bool) assert isinstance(allow_nan, bool) assert width in (16, 32, 64) self.allow_infinity = allow_infinity self.allow_nan = allow_nan self.width = width self.nasty_floats = [ float_of(f, self.width) for f in NASTY_FLOATS if self.permitted(f) ] weights = [0.2 * len(self.nasty_floats)] + [0.8] * len(self.nasty_floats) self.sampler = d.Sampler(weights)
def rule( *, targets: Union[Sequence[Bundle[Ex]], _OmittedArgument] = (), target: Optional[Bundle[Ex]] = None, **kwargs: SearchStrategy, ) -> Union[_RuleWrapper[Ex], Callable[[Callable[..., None]], Callable[..., None]]]: """Decorator for RuleBasedStateMachine. Any Bundle present in ``target`` or ``targets`` will define where the end result of this function should go. If both are empty then the end result will be discarded. ``target`` must be a Bundle, or if the result should go to multiple bundles you can pass a tuple of them as the ``targets`` argument. It is invalid to use both arguments for a single rule. If the result should go to exactly one of several bundles, define a separate rule for each case. kwargs then define the arguments that will be passed to the function invocation. If their value is a Bundle, or if it is ``consumes(b)`` where ``b`` is a Bundle, then values that have previously been produced for that bundle will be provided. If ``consumes`` is used, the value will also be removed from the bundle. Any other kwargs should be strategies and values from them will be provided. """ converted_targets = _convert_targets(targets, target) for k, v in kwargs.items(): check_strategy(v, name=k) def accept(f): if getattr(f, INVARIANT_MARKER, None): raise InvalidDefinition( "A function cannot be used for both a rule and an invariant.", Settings.default, ) existing_rule = getattr(f, RULE_MARKER, None) existing_initialize_rule = getattr(f, INITIALIZE_RULE_MARKER, None) if existing_rule is not None or existing_initialize_rule is not None: raise InvalidDefinition( "A function cannot be used for two distinct rules. ", Settings.default) preconditions = getattr(f, PRECONDITIONS_MARKER, ()) rule = Rule( targets=converted_targets, arguments=kwargs, function=f, preconditions=preconditions, ) @proxies(f) def rule_wrapper(*args, **kwargs): return f(*args, **kwargs) setattr(rule_wrapper, RULE_MARKER, rule) return rule_wrapper return accept
def __init__(self, machine): SearchStrategy.__init__(self) self.machine = machine self.rules = list(machine.rules()) self.enabled_rules_strategy = st.shared(FeatureStrategy(), key=("enabled rules", machine)) # The order is a bit arbitrary. Primarily we're trying to group rules # that write to the same location together, and to put rules with no # target first as they have less effect on the structure. We order from # fewer to more arguments on grounds that it will plausibly need less # data. This probably won't work especially well and we could be # smarter about it, but it's better than just doing it in definition # order. self.rules.sort(key=lambda rule: ( sorted(rule.targets), len(rule.arguments), rule.function.__name__, ))
def initialize( *, targets: Union[Sequence[Bundle[Ex]], _OmittedArgument] = (), target: Optional[Bundle[Ex]] = None, **kwargs: SearchStrategy, ) -> Union[_RuleWrapper[Ex], Callable[[Callable[..., None]], Callable[..., None]]]: """Decorator for RuleBasedStateMachine. An initialize decorator behaves like a rule, but all ``@initialize()`` decorated methods will be called before any ``@rule()`` decorated methods, in an arbitrary order. Each ``@initialize()`` method will be called exactly once per run, unless one raises an exception - after which only the ``.teardown()`` method will be run. ``@initialize()`` methods may not have preconditions. """ converted_targets = _convert_targets(targets, target) for k, v in kwargs.items(): check_strategy(v, name=k) def accept(f): if getattr(f, INVARIANT_MARKER, None): raise InvalidDefinition( "A function cannot be used for both a rule and an invariant.", Settings.default, ) existing_rule = getattr(f, RULE_MARKER, None) existing_initialize_rule = getattr(f, INITIALIZE_RULE_MARKER, None) if existing_rule is not None or existing_initialize_rule is not None: raise InvalidDefinition( "A function cannot be used for two distinct rules. ", Settings.default) preconditions = getattr(f, PRECONDITIONS_MARKER, ()) if preconditions: raise InvalidDefinition( "An initialization rule cannot have a precondition. ", Settings.default) rule = Rule( targets=converted_targets, arguments=kwargs, function=f, preconditions=preconditions, ) @proxies(f) def rule_wrapper(*args, **kwargs): return f(*args, **kwargs) setattr(rule_wrapper, INITIALIZE_RULE_MARKER, rule) return rule_wrapper return accept
def __init__(self, strategies): SearchStrategy.__init__(self) self.element_strategies = tuple(strategies)
def __init__(self, start, end): SearchStrategy.__init__(self) self.start = start self.end = end
def __init__(self, definition): SearchStrategy.__init__(self) self.__wrapped_strategy = None self.__in_repr = False self.__definition = definition