def test_characters_of_specific_groups(): st = characters(whitelist_categories=("Lu", "Nd")) find_any(st, lambda c: unicodedata.category(c) == "Lu") find_any(st, lambda c: unicodedata.category(c) == "Nd") assert_no_examples(st, lambda c: unicodedata.category(c) not in ("Lu", "Nd"))
def test_exclude_characters_of_specific_groups(): st = characters(blacklist_categories=("Lu", "Nd")) find_any(st, lambda c: unicodedata.category(c) != "Lu") find_any(st, lambda c: unicodedata.category(c) != "Nd") assert_no_examples(st, lambda c: unicodedata.category(c) in ("Lu", "Nd"))
def test_exclude_characters_of_specific_groups(): st = characters(blacklist_categories=('Lu', 'Nd')) find(st, lambda c: unicodedata.category(c) != 'Lu') find(st, lambda c: unicodedata.category(c) != 'Nd') assert_no_examples(st, lambda c: unicodedata.category(c) in ('Lu', 'Nd'))
def test_blacklisted_characters(): bad_chars = u'te02тест49st' st = characters(min_codepoint=ord('0'), max_codepoint=ord('9'), blacklist_characters=bad_chars) assert '1' == find(st, lambda c: True) assert_no_examples(st, lambda c: c in bad_chars)
def test_characters_of_specific_groups(): st = characters(whitelist_categories=('Lu', 'Nd')) find(st, lambda c: unicodedata.category(c) == 'Lu') find(st, lambda c: unicodedata.category(c) == 'Nd') assert_no_examples( st, lambda c: unicodedata.category(c) not in ('Lu', 'Nd'))
def test_characters_of_specific_groups(): st = characters(whitelist_categories=('Lu', 'Nd')) find(st, lambda c: unicodedata.category(c) == 'Lu') find(st, lambda c: unicodedata.category(c) == 'Nd') assert_no_examples(st, lambda c: unicodedata.category(c) not in ('Lu', 'Nd'))
def test_allow_subnormal_defaults_correctly(kwargs): allow_subnormal = kwargs.pop("allow_subnormal") strat = floats(**kwargs).filter(lambda x: x != 0) if allow_subnormal: find_any(strat, lambda x: -float_info.min < x < float_info.min) else: assert_no_examples(strat, lambda x: -float_info.min < x < float_info.min)
def test_subnormal_generation(xp, xps, kwargs): """Generation of subnormals is dependent on FTZ behaviour of array module.""" strat = xps.from_dtype(xp.float32, **kwargs).filter(lambda n: n != 0) if flushes_to_zero(xp, width=32): assert_no_examples(strat, lambda n: -smallest_normal < n < smallest_normal) else: find_any(strat, lambda n: -smallest_normal < n < smallest_normal)
def test_whitelist_characters_disjoint_blacklist_characters(): good_chars = u'123abc' bad_chars = u'456def' st = characters(min_codepoint=ord('0'), max_codepoint=ord('9'), blacklist_characters=bad_chars, whitelist_characters=good_chars) assert_no_examples(st, lambda c: c in bad_chars)
def test_whitelisted_characters_override(): good_characters = u'teтестst' st = characters(min_codepoint=ord('0'), max_codepoint=ord('9'), whitelist_characters=good_characters) find_any(st, lambda c: c in good_characters) find_any(st, lambda c: c in '0123456789') assert_no_examples(st, lambda c: c not in good_characters + '0123456789')
def test_blacklisted_characters(): bad_chars = u"te02тест49st" st = characters( min_codepoint=ord("0"), max_codepoint=ord("9"), blacklist_characters=bad_chars ) assert "1" == minimal(st, lambda c: True) assert_no_examples(st, lambda c: c in bad_chars)
def test_blacklisted_characters(): bad_chars = "te02тест49st" st = characters(min_codepoint=ord("0"), max_codepoint=ord("9"), blacklist_characters=bad_chars) assert "1" == minimal(st, lambda c: True) assert_no_examples(st, lambda c: c in bad_chars)
def test_subpattern_flags(): strategy = st.from_regex(u'(?i)a(?-i:b)') # "a" is case insensitive find_any(strategy, lambda s: s[0] == u'a') find_any(strategy, lambda s: s[0] == u'A') # "b" is case sensitive find_any(strategy, lambda s: s[1] == u'b') assert_no_examples(strategy, lambda s: s[1] == u'B')
def test_subpattern_flags(): strategy = st.from_regex("(?i)\\Aa(?-i:b)\\Z") # "a" is case insensitive find_any(strategy, lambda s: s[0] == "a") find_any(strategy, lambda s: s[0] == "A") # "b" is case sensitive find_any(strategy, lambda s: s[1] == "b") assert_no_examples(strategy, lambda s: s[1] == "B")
def test_subpattern_flags(): strategy = st.from_regex(u"(?i)\\Aa(?-i:b)\\Z") # "a" is case insensitive find_any(strategy, lambda s: s[0] == u"a") find_any(strategy, lambda s: s[0] == u"A") # "b" is case sensitive find_any(strategy, lambda s: s[1] == u"b") assert_no_examples(strategy, lambda s: s[1] == u"B")
def test_whitelist_characters_disjoint_blacklist_characters(): good_chars = u"123abc" bad_chars = u"456def" st = characters( min_codepoint=ord("0"), max_codepoint=ord("9"), blacklist_characters=bad_chars, whitelist_characters=good_chars, ) assert_no_examples(st, lambda c: c in bad_chars)
def test_whitelist_characters_disjoint_blacklist_characters(): good_chars = "123abc" bad_chars = "456def" st = characters( min_codepoint=ord("0"), max_codepoint=ord("9"), blacklist_characters=bad_chars, whitelist_characters=good_chars, ) assert_no_examples(st, lambda c: c in bad_chars)
def test_whitelisted_characters_override(): good_characters = "teтестst" st = characters( min_codepoint=ord("0"), max_codepoint=ord("9"), whitelist_characters=good_characters, ) find_any(st, lambda c: c in good_characters) find_any(st, lambda c: c in "0123456789") assert_no_examples(st, lambda c: c not in good_characters + "0123456789")
def test_whitelisted_characters_override(): good_characters = u"teтестst" st = characters( min_codepoint=ord("0"), max_codepoint=ord("9"), whitelist_characters=good_characters, ) find_any(st, lambda c: c in good_characters) find_any(st, lambda c: c in "0123456789") assert_no_examples(st, lambda c: c not in good_characters + "0123456789")
def test_caret_in_the_middle_does_not_generate_anything(): r = re.compile("a^b") assert_no_examples(st.from_regex(r))
def test_exclude_characters_of_major_categories(): st = characters(blacklist_categories=("L", "N")) find_any(st, lambda c: not unicodedata.category(c).startswith("L")) find_any(st, lambda c: not unicodedata.category(c).startswith("N")) assert_no_examples(st, lambda c: unicodedata.category(c)[0] in ("L", "N"))
def test_assume_in_just_raises_immediately(): assert_no_examples(st.just(1).map(lambda x: assume(x == 2)))
def test_no_examples(): assert_no_examples(st.nothing())
def test_negative_lookahead(): # no efficient support strategy = st.from_regex("^ab(?!cd)[abcd]*") assert_all_examples(strategy, lambda s: not s.startswith("abcd")) assert_no_examples(strategy, lambda s: s.startswith("abcd"))
def test_one_of_empty(): e = st.one_of() assert e.is_empty assert_no_examples(e)
def test_self_tuple_draws_nothing(): x = st.deferred(lambda: st.tuples(x)) assert_no_examples(x)
def test_self_recursive_flatmap(): bad = st.deferred(lambda: bad.flatmap(lambda x: st.none())) assert_no_examples(bad)
def test_hidden_self_references_just_result_in_no_example(): bad = st.deferred(lambda: st.none().flatmap(lambda _: bad)) assert_no_examples(bad)
def test_mutually_recursive_tuples_draw_nothing(): x = st.deferred(lambda: st.tuples(y)) y = st.tuples(x) assert_no_examples(x) assert_no_examples(y)
def test_find_something_rare(): st = characters(whitelist_categories=['Zs'], min_codepoint=12288) find(st, lambda c: unicodedata.category(c) == 'Zs') assert_no_examples(st, lambda c: unicodedata.category(c) != 'Zs')
def test_impossible_negative_lookahead(): assert_no_examples(st.from_regex("(?!foo)foo"))
def test_negative_lookbehind(): # no efficient support strategy = st.from_regex("[abc]*(?<!abc)d") assert_all_examples(strategy, lambda s: not s.endswith("abcd")) assert_no_examples(strategy, lambda s: s.endswith("abcd"))
def test_no_nil_uuid_by_default(): assert_no_examples(st.uuids(), lambda x: x == uuid.UUID(int=0))
def test_subsequence_of_empty(): sub_seq_strat = st.lists(st.none(), max_size=0) assert_no_examples(sub_seq_strat)
def test_example_raises_unsatisfiable_when_too_filtered(): assert_no_examples(integers().filter(lambda x: False))
def test_caret_in_the_middle_does_not_generate_anything(): r = re.compile(u'a^b') assert_no_examples(st.from_regex(r))
def test_impossible_negative_lookahead(): assert_no_examples(st.from_regex(u'(?!foo)foo'))
def test_negative_lookbehind(): # no efficient support strategy = st.from_regex(u'[abc]*(?<!abc)d') assert_all_examples(strategy, lambda s: not s.endswith(u'abcd')) assert_no_examples(strategy, lambda s: s.endswith(u'abcd'))
def test_negative_lookahead(): # no efficient support strategy = st.from_regex(u'^ab(?!cd)[abcd]*') assert_all_examples(strategy, lambda s: not s.startswith(u'abcd')) assert_no_examples(strategy, lambda s: s.startswith(u'abcd'))
def test_characters_of_major_categories(): st = characters(whitelist_categories=('L', 'N')) find_any(st, lambda c: unicodedata.category(c).startswith('L')) find_any(st, lambda c: unicodedata.category(c).startswith('N')) assert_no_examples( st, lambda c: unicodedata.category(c)[0] not in ('L', 'N'))