def steps(self): strategies = [] for rule in self.rules(): converted_arguments = {} valid = True if rule.precondition and not rule.precondition(self): continue for k, v in sorted(rule.arguments.items()): if isinstance(v, Bundle): bundle = self.bundle(v.name) if not bundle: valid = False break converted_arguments[k] = v if valid: strategies.append(TupleStrategy(( just(rule), FixedKeysDictStrategy(converted_arguments) ), tuple)) if not strategies: raise InvalidDefinition( u'No progress can be made from state %r' % (self,) ) for name, bundle in self.bundles.items(): if len(bundle) > 1: strategies.append( builds( ShuffleBundle, just(name), lists(integers(0, len(bundle) - 1)))) return one_of(strategies)
def steps(self): strategies = [] for rule in self.rules(): converted_arguments = {} valid = True if rule.precondition is not None and not rule.precondition(self): continue for k, v in sorted(rule.arguments.items()): if isinstance(v, Bundle): bundle = self.bundle(v.name) if not bundle: valid = False break else: v = sampled_from(bundle) converted_arguments[k] = v if valid: strategies.append( TupleStrategy((just(rule), FixedKeysDictStrategy(converted_arguments)), tuple)) if not strategies: raise InvalidDefinition(u'No progress can be made from state %r' % (self, )) return one_of(*strategies)
def fixed_dictionaries(mapping): """Generate a dictionary of the same type as mapping with a fixed set of keys mapping to strategies. mapping must be a dict subclass. Generated values have all keys present in mapping, with the corresponding values drawn from mapping[key]. If mapping is an instance of OrderedDict the keys will also be in the same order, otherwise the order is arbitrary. """ from hypothesis.searchstrategy.collections import FixedKeysDictStrategy check_type(dict, mapping) for v in mapping.values(): check_type(SearchStrategy, v) return FixedKeysDictStrategy(mapping)
def steps(self): strategies = [] for rule in self.rules(): converted_arguments = {} valid = True for k, v in rule.arguments.items(): if isinstance(v, Bundle): bundle = self.bundle(v.name) if not bundle: valid = False break else: v = SimpleSampledFromStrategy(bundle) converted_arguments[k] = v if valid: strategies.append( TupleStrategy((JustStrategy(rule), FixedKeysDictStrategy(converted_arguments)), tuple)) if not strategies: raise InvalidDefinition('No progress can be made from state %r' % (self, )) return one_of_strategies(strategies)