def test_can_safely_mix_simplifiers(): from hypothesis.searchstrategy.strings import OneCharStringStrategy from hypothesis.internal.debug import some_template s = OneCharStringStrategy() r = Random(1) t1 = some_template(s, r) while True: t2 = some_template(s, r) if t1 != t2: break for u in (t1, t2): for v in (t1, t2): for simplify in s.simplifiers(r, u): for w in simplify(r, v): assert not s.strictly_simpler(v, w)
def text( alphabet=None, min_size=None, average_size=None, max_size=None ): """Generates values of a unicode text type (unicode on python 2, str on python 3) with values drawn from alphabet, which should be an iterable of length one strings or a strategy generating such. If it is None it will default to generating the full unicode range. If it is an empty collection this will only generate empty strings. min_size, max_size and average_size have the usual interpretations. """ from hypothesis.searchstrategy.strings import OneCharStringStrategy, \ StringStrategy if alphabet is None: char_strategy = OneCharStringStrategy() elif not alphabet: if (min_size or 0) > 0: raise InvalidArgument( u'Invalid min_size %r > 0 for empty alphabet' % ( min_size, ) ) return just(u'') elif isinstance(alphabet, SearchStrategy): char_strategy = alphabet else: char_strategy = sampled_from(list(map(text_type, alphabet))) return StringStrategy(lists( char_strategy, average_size=average_size, min_size=min_size, max_size=max_size ))
def characters(whitelist_categories=None, blacklist_categories=None, blacklist_characters=None, min_codepoint=None, max_codepoint=None): """Generates unicode text type (unicode on python 2, str on python 3) characters following specified filtering rules. This strategy accepts lists of Unicode categories, characters of which should (`whitelist_categories`) or should not (`blacklist_categories`) be produced. Also there could be applied limitation by minimal and maximal produced code point of the characters. If you know what exactly characters you don't want to be produced, pass them with `blacklist_characters` argument. """ if (min_codepoint is not None and max_codepoint is not None and min_codepoint > max_codepoint): raise InvalidArgument( 'Cannot have min_codepoint=%d > max_codepoint=%d ' % (min_codepoint, max_codepoint)) from hypothesis.searchstrategy.strings import OneCharStringStrategy return OneCharStringStrategy(whitelist_categories=whitelist_categories, blacklist_categories=blacklist_categories, blacklist_characters=blacklist_characters, min_codepoint=min_codepoint, max_codepoint=max_codepoint)