Esempio n. 1
0
def test_groups(pattern, is_unicode, invert):
    if u'd' in pattern.lower():
        group_pred = is_digit
    elif u'w' in pattern.lower():
        group_pred = is_word
    else:
        # Special behaviour due to \x1c, INFORMATION SEPARATOR FOUR
        group_pred = is_unicode_space if is_unicode else is_space

    if invert:
        pattern = pattern.swapcase()
        _p = group_pred

        def group_pred(s):
            return not _p(s)

    pattern = u'^%s\\Z' % (pattern,)

    compiler = unicode_regex if is_unicode else ascii_regex
    strategy = st.from_regex(compiler(pattern))

    find_any(strategy.filter(group_pred), is_ascii)
    if is_unicode:
        find_any(strategy, lambda s: group_pred(s) and not is_ascii(s))

    assert_all_examples(strategy, group_pred)
def test_groupref_exists():
    assert_all_examples(
        st.from_regex(u"^(<)?a(?(1)>)$"),
        lambda s: s in (u"a", u"a\n", u"<a>", u"<a>\n"),
    )
    assert_all_examples(
        st.from_regex(u"^(a)?(?(1)b|c)$"), lambda s: s in (u"ab", u"ab\n", u"c", u"c\n")
    )
Esempio n. 3
0
def test_groupref_exists():
    assert_all_examples(
        st.from_regex(u'^(<)?a(?(1)>)$'),
        lambda s: s in (u'a', u'a\n', u'<a>', u'<a>\n')
    )
    assert_all_examples(
        st.from_regex(u'^(a)?(?(1)b|c)$'),
        lambda s: s in (u'ab', u'ab\n', u'c', u'c\n')
    )
def test_step_stays_within_bounds(size):
    # indices -> (start, stop, step)
    # Stop is exclusive so we use -1 as the floor.
    # This uses the indices that slice produces to make this test more readable
    # due to how splice processes None being a little complex
    assert_all_examples(
        st.slices(size),
        lambda x: (
            x.indices(size)[0] + x.indices(size)[2] <= size
            and x.indices(size)[0] + x.indices(size)[2] >= -1
        )
        or x.start == x.stop,
    )
Esempio n. 5
0
def test_can_generate(pattern, encode):
    if encode:
        pattern = pattern.encode('ascii')
    assert_all_examples(st.from_regex(pattern), re.compile(pattern).search)
Esempio n. 6
0
def test_timezone_lookup(type_):
    assert issubclass(type_, datetime.tzinfo)
    assert_all_examples(st.from_type(type_), lambda t: isinstance(t, type_))
Esempio n. 7
0
def test_typevars_can_be_redefined():
    """We test that one can register a custom strategy for all type vars."""
    A = typing.TypeVar("A")

    with temp_registered(typing.TypeVar, st.just(1)):
        assert_all_examples(st.from_type(A), lambda obj: obj == 1)
Esempio n. 8
0
def test_fullmatch_matches(pattern, eqiv_pattern):
    assert_all_examples(st.from_regex(pattern, fullmatch=True),
                        lambda s: re.match(eqiv_pattern, s))
def test_start_stay_within_bounds(size):
    assert_all_examples(
        st.slices(size), lambda x: x.start is None or (x.start >= 0 and x.start <= size)
    )
def test_not_literal_with_ignorecase(pattern):
    assert_all_examples(
        st.from_regex(pattern),
        lambda s: s[0] not in (u"a", u"A") and s[1] not in (u"b", u"B"),
    )
Esempio n. 11
0
def test_can_generate(pattern, encode):
    if encode:
        pattern = pattern.encode('ascii')
    assert_all_examples(st.from_regex(pattern), re.compile(pattern).search)
Esempio n. 12
0
def test_can_generate_integer_dtypes(xp, xps):
    int_dtypes = [getattr(xp, name) for name in INT_NAMES]
    assert_all_examples(xps.integer_dtypes(),
                        lambda dtype: dtype in int_dtypes)
Esempio n. 13
0
def test_can_generate_numeric_dtypes(xp, xps):
    numeric_dtypes = [getattr(xp, name) for name in NUMERIC_NAMES]
    assert_all_examples(xps.numeric_dtypes(),
                        lambda dtype: dtype in numeric_dtypes)
Esempio n. 14
0
def test_can_generate_boolean_dtypes(xp, xps):
    assert_all_examples(xps.boolean_dtypes(), lambda dtype: dtype == xp.bool)
Esempio n. 15
0
def test_can_generate_scalar_dtypes(xp, xps):
    dtypes = [getattr(xp, name) for name in DTYPE_NAMES]
    assert_all_examples(xps.scalar_dtypes(), lambda dtype: dtype in dtypes)
def test_any_doesnt_generate_newline():
    assert_all_examples(st.from_regex(u"\\A.\\Z"), lambda s: s != u"\n")
Esempio n. 17
0
def test_any_doesnt_generate_newline():
    assert_all_examples(st.from_regex(u'.'), lambda s: s != u'\n')
Esempio n. 18
0
def test_can_generate_unsigned_integer_dtypes(xp, xps):
    uint_dtypes = [getattr(xp, name) for name in UINT_NAMES]
    assert_all_examples(xps.unsigned_integer_dtypes(),
                        lambda dtype: dtype in uint_dtypes)
Esempio n. 19
0
def test_groupref_exists():
    assert_all_examples(st.from_regex(u'^(<)?a(?(1)>)$'), lambda s: s in
                        (u'a', u'a\n', u'<a>', u'<a>\n'))
    assert_all_examples(st.from_regex(u'^(a)?(?(1)b|c)$'), lambda s: s in
                        (u'ab', u'ab\n', u'c', u'c\n'))
Esempio n. 20
0
def test_can_generate_floating_dtypes(xp, xps):
    float_dtypes = [getattr(xp, name) for name in FLOAT_NAMES]
    assert_all_examples(xps.floating_dtypes(),
                        lambda dtype: dtype in float_dtypes)
Esempio n. 21
0
def test_any_doesnt_generate_newline():
    assert_all_examples(st.from_regex(u'.'), lambda s: s != u'\n')
Esempio n. 22
0
def test_size_is_equal_0():
    assert_all_examples(
        st.slices(0), lambda x: x.step != 0 and x.start is None and x.stop is None
    )
Esempio n. 23
0
def test_can_handle_binary_regex_which_is_not_ascii():
    bad = b'\xad'
    assert_all_examples(st.from_regex(bad), lambda x: bad in x)
Esempio n. 24
0
def test_generic_origin_concrete_builds():
    with temp_registered(MyGeneric, st.builds(MyGeneric, st.integers())):
        assert_all_examples(st.builds(using_generic),
                            lambda example: isinstance(example, int))
Esempio n. 25
0
def test_fullmatch_matches(pattern, eqiv_pattern):
    assert_all_examples(st.from_regex(pattern, fullmatch=True),
                        lambda s: re.match(eqiv_pattern, s))
Esempio n. 26
0
def test_stop_stays_within_bounds(size):
    assert_all_examples(
        st.slices(size),
        lambda x: x.stop is None or (x.stop >= 0 and x.stop <= size))
Esempio n. 27
0
def test_generic_collections_only_use_hashable_elements(typ):
    assert_all_examples(from_type(typ), lambda x: True)
Esempio n. 28
0
def test_start_stay_within_bounds(size):
    assert_all_examples(
        st.slices(size),
        lambda x: x.start is None or (x.start >= 0 and x.start <= size))
Esempio n. 29
0
def test_typevars_can_be_redefine_with_factory():
    """We test that one can register a custom strategy for all type vars."""
    A = typing.TypeVar("A")

    with temp_registered(typing.TypeVar, lambda thing: st.just(thing.__name__)):
        assert_all_examples(st.from_type(A), lambda obj: obj == "A")
Esempio n. 30
0
def test_step_will_not_be_zero(size):
    assert_all_examples(st.slices(size), lambda x: x.step != 0)
Esempio n. 31
0
def test_cannot_generate_newaxis_when_disabled(xp, xps):
    """Strategy does not generate newaxis when disabled (i.e. the default)."""
    assert_all_examples(xps.indices((3, 3, 3)), lambda idx: None not in idx)
Esempio n. 32
0
def test_can_generate(pattern, encode):
    if encode:
        pattern = pattern.encode("ascii")
    with local_settings(
            settings(suppress_health_check=[HealthCheck.data_too_large])):
        assert_all_examples(st.from_regex(pattern), re.compile(pattern).search)
Esempio n. 33
0
def test_not_literal_with_ignorecase(pattern):
    assert_all_examples(
        st.from_regex(pattern), lambda s: s[0] not in
        (u'a', u'A') and s[1] not in (u'b', u'B'))
Esempio n. 34
0
def test_not_literal_with_ignorecase(pattern):
    assert_all_examples(
        st.from_regex(pattern),
        lambda s: s[0] not in ("a", "A") and s[1] not in ("b", "B"),
    )
Esempio n. 35
0
def test_end_with_terminator_does_not_pad():
    assert_all_examples(st.from_regex(u'abc\\Z'), lambda x: x[-3:] == u"abc")
Esempio n. 36
0
def test_any_doesnt_generate_newline():
    assert_all_examples(st.from_regex("\\A.\\Z"), lambda s: s != "\n")
Esempio n. 37
0
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'))
Esempio n. 38
0
def test_end_with_terminator_does_not_pad():
    assert_all_examples(st.from_regex(u'abc\Z'), lambda x: x[-3:] == u"abc")
Esempio n. 39
0
def test_not_literal_with_ignorecase(pattern):
    assert_all_examples(
        st.from_regex(pattern),
        lambda s: s[0] not in (u'a', u'A') and s[1] not in (u'b', u'B')
    )
Esempio n. 40
0
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'))
Esempio n. 41
0
def test_groupref_exists():
    assert_all_examples(st.from_regex("^(<)?a(?(1)>)$"), lambda s: s in
                        ("a", "a\n", "<a>", "<a>\n"))
    assert_all_examples(st.from_regex("^(a)?(?(1)b|c)$"), lambda s: s in
                        ("ab", "ab\n", "c", "c\n"))
def test_step_will_not_be_zero(size):
    assert_all_examples(st.slices(size), lambda x: x.step != 0)
Esempio n. 43
0
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"))
Esempio n. 44
0
def test_can_handle_binary_regex_which_is_not_ascii():
    bad = b"\xad"
    assert_all_examples(st.from_regex(bad), lambda x: bad in x)
Esempio n. 45
0
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'))
Esempio n. 46
0
def test_does_not_left_pad_beginning_of_string_marker():
    assert_all_examples(st.from_regex("\\Afoo"), lambda x: x.startswith("foo"))
Esempio n. 47
0
def test_does_not_left_pad_beginning_of_string_marker():
    assert_all_examples(
        st.from_regex(u'\\Afoo'), lambda x: x.startswith(u'foo'))
def test_stop_stays_within_bounds(size):
    assert_all_examples(
        st.slices(size), lambda x: x.stop is None or (x.stop >= 0 and x.stop <= size)
    )