コード例 #1
0
ファイル: test_utils.py プロジェクト: InSertCod3/natsort
def test__natsort_key_with_float_and_unsigned_splits_input_into_string_and_unsigned_float(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert ns.U == ns.UNSIGNED
    assert _natsort_key(s, None, ns.F | ns.U) == tuple(_number_extracter(s, _float_nosign_exp_re, *float_nosafe_nolocale_nogroup))
    # Default is unsigned search
    assert _natsort_key(s, None, ns.F) == tuple(_number_extracter(s, _float_nosign_exp_re, *float_nosafe_nolocale_nogroup))
コード例 #2
0
def test__natsort_key_with_tuple_input_returns_nested_tuples(x):
    # Iterables are parsed recursively so you can sort lists of lists.
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = tuple(_number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    assert _natsort_key((s, s), None, ns.I) == (t, t)
コード例 #3
0
def test_parse_string_function_parses_float_with_sign_exp_float(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    assume(all(whitespace_check(y) for y in x))
    s = "".join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _parse_string_function(0, "", _float_sign_exp_re.split, no_op, fast_float, tuple2)(s) == float_splitter(
        s, True, True, ""
    )
コード例 #4
0
def test_locale_convert_transforms_float_string_to_float_with_de_locale(x):
    assume(not isnan(x))
    load_locale('de_DE')
    assert locale_convert(repr(x), (fast_float, isfloat), False) == x
    assert locale_convert(
        repr(x).replace('.', ','), (fast_float, isfloat), False) == x
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #5
0
def test_post_split_function_with_LOCALE_and_GROUPLETTERS_returns_fast_int_and_groupletters_and_locale_convert(x):
    assume(x)
    try:
        assert _post_split_function(ns.GROUPLETTERS | ns.LOCALE)(x) == fast_int(x, key=lambda x: get_strxfrm()(_groupletters(x)))
    except ValueError as e:  # handle broken locale lib on BSD.
        if 'is not in range' not in str(e):
            raise
コード例 #6
0
ファイル: test_main.py プロジェクト: InSertCod3/natsort
def test_keep_entry_range_returns_False_if_no_portion_of_input_is_between_the_range_bounds(
        x):
    s = ''.join(map(py23_str, x))
    assume(
        all(not (1 <= int(i) <= 20) for i in re.findall(r'\d+', s)
            if re.match(r'\d+$', i)))
    assert not keep_entry_range(s, [1], [20], int, re.compile(r'\d+'))
コード例 #7
0
def test_number_extracter_doubles_letters_with_lowercase_version_with_groupletters_for_float(x):
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = float_splitter(s, True, True, False, '')
    t = [''.join([low(z) + z for z in y]) if type(y) != float else y for y in t]
    assert _number_extracter(s, _float_sign_exp_re, *float_nosafe_nolocale_group) == t
コード例 #8
0
ファイル: test_main.py プロジェクト: InSertCod3/natsort
def test_exclude_entry_returns_False_if_exlcude_parameters_are_in_input(x):
    s = ''.join(map(py23_str, x))
    assume(
        any(
            int(i) in (23, 45, 87) for i in re.findall(r'\d+', s)
            if re.match(r'\d+$', i)))
    assert not exclude_entry(s, [23, 45, 87], int, re.compile(r'\d+'))
コード例 #9
0
def test__natsort_key_with_version_or_digit_matches_usigned_int(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _natsort_key(s, None,
                        ns.VERSION) == _natsort_key(s, None,
                                                    ns.INT | ns.UNSIGNED)
    assert _natsort_key(s, None, ns.DIGIT) == _natsort_key(s, None, ns.VERSION)
コード例 #10
0
def test__natsort_key_with_float_and_signed_splits_input_into_string_and_signed_float_with_exponent(x):
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert ns.F == ns.FLOAT
    assert ns.S == ns.SIGNED
    assert _natsort_key(s, None, ns.F | ns.S) == tuple(_number_extracter(s, _float_sign_exp_re, *float_nosafe_nolocale_nogroup))
コード例 #11
0
def test__natsort_key_with_tuple_input_returns_nested_tuples(x):
    # Iterables are parsed recursively so you can sort lists of lists.
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = tuple(
        _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    assert _natsort_key((s, s), None, ns.I) == (t, t)
コード例 #12
0
ファイル: test_main.py プロジェクト: InSertCod3/natsort
def test_keep_entry_range_returns_True_if_any_portion_of_input_is_between_any_range_bounds(
        x):
    s = ''.join(map(py23_str, x))
    assume(
        any((1 < int(i) < 20) or (88 < int(i) < 90)
            for i in re.findall(r'\d+', s) if re.match(r'\d+$', i)))
    assert keep_entry_range(s, [1, 88], [20, 90], int, re.compile(r'\d+'))
コード例 #13
0
def test_path_splitter_splits_path_string_by_separator_and_removes_extension(
        x):
    assume(all(x))
    z = py23_str(pathlib.Path(*x[:-2])) + '.' + x[-1]
    y = list(pathlib.Path(z).parts)
    assert _path_splitter(z) == y[:-1] + [pathlib.Path(z).stem
                                          ] + [pathlib.Path(z).suffix]
コード例 #14
0
ファイル: test_utils.py プロジェクト: InSertCod3/natsort
def test__natsort_key_with_IGNORECASE_lowercases_text(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    try:
        assert _natsort_key(s, None, ns.IGNORECASE) == tuple(_number_extracter(s.casefold(), _int_nosign_re, *int_nosafe_nolocale_nogroup))
    except AttributeError:
        assert _natsort_key(s, None, ns.IGNORECASE) == tuple(_number_extracter(s.lower(), _int_nosign_re, *int_nosafe_nolocale_nogroup))
コード例 #15
0
def test__natsort_key_with_float_and_noexp_splits_input_into_string_and_unsigned_float_without_exponent(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _natsort_key(s, None, ns.F | ns.N) == tuple(
        _number_extracter(s, _float_nosign_noexp_re,
                          *float_nosafe_nolocale_nogroup))
コード例 #16
0
def test__natsort_key_with_GROUPLETTERS_and_LOWERCASEFIRST_inverts_text_first_then_doubles_letters_with_lowercase_letter_first(x):
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(ichain([repr(y)] if type(y) in (float, long, int) else [low(y), y] for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = _number_extracter(s.swapcase(), _int_nosign_re, *int_nosafe_nolocale_nogroup)
    assert _natsort_key(s, None, ns.G | ns.LF) == tuple(''.join(low(z) + z for z in y) if type(y) not in (float, long, int) else y for y in t)
コード例 #17
0
def test_number_extracter_inserts_empty_string_between_floats_for_py3safe_option(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _number_extracter(s, _float_sign_exp_re,
                             *float_safe_nolocale_nogroup) == float_splitter(
                                 s, True, True, True, '')
コード例 #18
0
def test_number_extracter_excludes_plus_sign_and_exponent_in_float_definition_for_unsigned_noexp_floats(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _number_extracter(s, _float_nosign_noexp_re,
                             *float_nosafe_nolocale_nogroup) == float_splitter(
                                 s, False, False, False, '')
コード例 #19
0
def test__natsort_key_with_LOCALE_and_UNGROUPLETTERS_places_space_before_string_with_capital_first_letter(
        x):
    # Locale aware sorting
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    load_locale('en_US')
    if dumb_sort():
        t = tuple(
            _number_extracter(s.swapcase(), _float_nosign_exp_re,
                              *float_nosafe_locale_group))
    else:
        t = tuple(
            _number_extracter(s, _float_nosign_exp_re,
                              *float_nosafe_locale_nogroup))
    if not t:
        r = (t, t)
    elif t[0] in (null_string, get_strxfrm()(b'\x00')
                  if sys.version[0] == '2' and not use_pyicu else null_string):
        r = ((b'' if use_pyicu else '', ), t)
    else:
        r = ((s[0], ), t)
    assert _natsort_key(s, None, ns.LOCALE | ns.UNGROUPLETTERS | ns.F) == r
    # The below are all aliases for UNGROUPLETTERS
    assert ns.UNGROUPLETTERS == ns.UG
    assert ns.UNGROUPLETTERS == ns.CAPITALFIRST
    assert ns.UNGROUPLETTERS == ns.C
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #20
0
def test__natsort_key_with_tuple_input_but_itemgetter_key_returns_split_second_element(x):
    # A key is applied before recursion, but not in the recursive calls.
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = tuple(_number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    assert _natsort_key((s, s), itemgetter(1), ns.I) == t
コード例 #21
0
def test__natsort_key_with_tuple_input_but_itemgetter_key_returns_split_second_element(
        x):
    # A key is applied before recursion, but not in the recursive calls.
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = tuple(
        _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    assert _natsort_key((s, s), itemgetter(1), ns.I) == t
コード例 #22
0
def test__natsort_key_with_int_splits_and_signed_input_into_string_and_signed_int(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _natsort_key(s, None, ns.INT | ns.SIGNED) == tuple(
        _number_extracter(s, _int_sign_re, *int_nosafe_nolocale_nogroup))
    assert _natsort_key(s, None, ns.SIGNED) == tuple(
        _number_extracter(s, _int_sign_re, *int_nosafe_nolocale_nogroup))
コード例 #23
0
def test_locale_convert_with_groupletters_transforms_nonfloat_string_to_strxfrm_string_with_grouped_letters(
        x):
    assume(type(fast_float(x)) is not float)
    load_locale('en_US')
    strxfrm = get_strxfrm()
    assert locale_convert(x, (fast_float, isfloat), True) == strxfrm(''.join(
        chain.from_iterable([low(y), y] for y in x)))
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #24
0
ファイル: test_utils.py プロジェクト: InSertCod3/natsort
def test__natsort_key_with_int_splits_input_into_string_and_unsigned_int(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert ns.I == ns.INT
    assert _natsort_key(s, None, ns.INT) == tuple(_number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    # Default is int search
    assert _natsort_key(s, None, ns.NOEXP) == tuple(_number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    # NOEXP is ignored for integers
    assert _natsort_key(s, None, ns.I | ns.NOEXP) == tuple(_number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
コード例 #25
0
def test_number_extracter_doubles_letters_with_lowercase_version_with_groupletters_for_float(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = float_splitter(s, True, True, False, '')
    t = [
        ''.join([low(z) + z for z in y]) if type(y) != float else y for y in t
    ]
    assert _number_extracter(s, _float_sign_exp_re,
                             *float_nosafe_nolocale_group) == t
コード例 #26
0
ファイル: test_utils.py プロジェクト: InSertCod3/natsort
def test__natsort_key_with_LOCALE_transforms_floats_according_to_the_current_locale_and_strxfrms_strings(x):
    # Locale aware sorting
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    load_locale('en_US')
    if dumb_sort():
        assert _natsort_key(s, None, ns.LOCALE | ns.F) == tuple(_number_extracter(s.swapcase(), _float_nosign_exp_re, *float_nosafe_locale_group))
    else:
        assert _natsort_key(s, None, ns.LOCALE | ns.F) == tuple(_number_extracter(s, _float_nosign_exp_re, *float_nosafe_locale_nogroup))
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #27
0
def test__natsort_key_with_IGNORECASE_lowercases_text(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    try:
        assert _natsort_key(s, None, ns.IGNORECASE) == tuple(
            _number_extracter(s.casefold(), _int_nosign_re,
                              *int_nosafe_nolocale_nogroup))
    except AttributeError:
        assert _natsort_key(s, None, ns.IGNORECASE) == tuple(
            _number_extracter(s.lower(), _int_nosign_re,
                              *int_nosafe_nolocale_nogroup))
コード例 #28
0
def test_number_extracter_extracts_numbers_and_strxfrms_letter_doubled_strings_with_use_locale_and_groupletters(x):
    assume(len(x) <= 10)
    load_locale('en_US')
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = int_splitter(s, False, False, null_string)
    try:  # Account for locale bug on Python 3.2
        t = [y if i == 0 and y is null_string else locale_convert(y, (fast_int, isint), True) for i, y in enumerate(t)]
        assert _number_extracter(s, _int_nosign_re, *int_nosafe_locale_group) == t
    except OverflowError:
        pass
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #29
0
def test__natsort_key_with_GROUPLETTERS_doubles_text_with_lowercase_letter_first(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(
        ichain([repr(y)] if type(y) in (float, long, int) else [low(y), y]
               for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    t = _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup)
    assert _natsort_key(s, None, ns.GROUPLETTERS) == tuple(''.join(
        low(z) + z for z in y) if type(y) not in (float, long, int) else y
                                                           for y in t)
コード例 #30
0
def test__natsort_key_with_float_and_unsigned_splits_input_into_string_and_unsigned_float(
        x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert ns.U == ns.UNSIGNED
    assert _natsort_key(s, None, ns.F | ns.U) == tuple(
        _number_extracter(s, _float_nosign_exp_re,
                          *float_nosafe_nolocale_nogroup))
    # Default is unsigned search
    assert _natsort_key(s, None, ns.F) == tuple(
        _number_extracter(s, _float_nosign_exp_re,
                          *float_nosafe_nolocale_nogroup))
コード例 #31
0
def test__natsort_key_with_int_splits_input_into_string_and_unsigned_int(x):
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert ns.I == ns.INT
    assert _natsort_key(s, None, ns.INT) == tuple(
        _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    # Default is int search
    assert _natsort_key(s, None, ns.NOEXP) == tuple(
        _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
    # NOEXP is ignored for integers
    assert _natsort_key(s, None, ns.I | ns.NOEXP) == tuple(
        _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_nogroup))
コード例 #32
0
def test__natsort_key_with_LOCALE_transforms_floats_according_to_the_current_locale_and_strxfrms_strings(
        x):
    # Locale aware sorting
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    load_locale('en_US')
    if dumb_sort():
        assert _natsort_key(s, None, ns.LOCALE | ns.F) == tuple(
            _number_extracter(s.swapcase(), _float_nosign_exp_re,
                              *float_nosafe_locale_group))
    else:
        assert _natsort_key(s, None, ns.LOCALE | ns.F) == tuple(
            _number_extracter(s, _float_nosign_exp_re,
                              *float_nosafe_locale_nogroup))
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #33
0
ファイル: test_utils.py プロジェクト: InSertCod3/natsort
def test__natsort_key_with_LOCALE_and_UNGROUPLETTERS_places_space_before_string_with_capital_first_letter(x):
    # Locale aware sorting
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    load_locale('en_US')
    if dumb_sort():
        t = tuple(_number_extracter(s.swapcase(), _float_nosign_exp_re, *float_nosafe_locale_group))
    else:
        t = tuple(_number_extracter(s, _float_nosign_exp_re, *float_nosafe_locale_nogroup))
    if not t:
        r = (t, t)
    elif t[0] in (null_string, get_strxfrm()(b'\x00') if sys.version[0] == '2' and not use_pyicu else null_string):
        r = ((b'' if use_pyicu else '',), t)
    else:
        r = ((s[0],), t)
    assert _natsort_key(s, None, ns.LOCALE | ns.UNGROUPLETTERS | ns.F) == r
    # The below are all aliases for UNGROUPLETTERS
    assert ns.UNGROUPLETTERS == ns.UG
    assert ns.UNGROUPLETTERS == ns.CAPITALFIRST
    assert ns.UNGROUPLETTERS == ns.C
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #34
0
def test_fast_int_leaves_float_string_as_is(x):
    assume(not x.is_integer())
    assert fast_int(repr(x)) == repr(x)
コード例 #35
0
def test_fast_float_converts_float_string_to_float(x):
    assume(not isnan(x))  # But inf is included
    assert fast_float(repr(x)) == x
コード例 #36
0
ファイル: test_main.py プロジェクト: InSertCod3/natsort
def test_check_filter_converts_filter_numbers_to_floats_if_filter_is_valid(
        x, y):
    assume(all(i < j for i, j in zip(x, y)))
    assert check_filter(list(zip(x, y))) == [(float(i), float(j))
                                             for i, j in zip(x, y)]
コード例 #37
0
def test_parse_number_function_with_PATH_UNGROUPLETTERS_LOCALE_makes_function_that_returns_nested_tuple(x):
    assume(not isnan(x))
    assert _parse_number_function(ns.PATH | ns.UNGROUPLETTERS | ns.LOCALE, '')(x) == ((('',), ('', x)),)
コード例 #38
0
def test_check_filter_raises_ValueError_if_filter_is_invalid(x, y):
    assume(any(float(i) >= float(j) for i, j in zip(x, y)))
    with raises(ValueError) as err:
        check_filter(list(zip(x, y)))
    assert str(err.value) == 'Error in --filter: low >= high'
コード例 #39
0
def test_keep_entry_range_returns_False_if_no_portion_of_input_is_between_the_range_bounds(x):
    s = ''.join(map(py23_str, x))
    assume(all(not (1 <= int(i) <= 20) for i in re.findall(r'\d+', s) if re.match(r'\d+$', i)))
    assert not keep_entry_range(s, [1], [20], int, re.compile(r'\d+'))
コード例 #40
0
def test_range_check_returns_range_as_is_but_with_floats_if_first_is_less_than_second(x, y):
    assume(float(x) < float(y))
    assert range_check(x, y) == (float(x), float(y))
コード例 #41
0
def test_range_check_raises_ValueError_if_second_is_less_than_first(x, y):
    assume(x >= y)
    with raises(ValueError) as err:
        range_check(x, x)
    assert str(err.value) == 'low >= high'
コード例 #42
0
def test_fast_float_converts_float_string_to_float(x):
    assume(not isnan(x))  # But inf is included
    assert fast_float(repr(x)) == x
コード例 #43
0
def test_fast_int_leaves_float_string_as_is(x):
    assume(not x.is_integer())
    assert fast_int(repr(x)) == repr(x)
コード例 #44
0
def test_fast_float_leaves_string_as_is(x):
    assume(not is_float(x))
    assume(bool(x))
    assert fast_float(x) == x
コード例 #45
0
def test__natsort_key_with_UNGROUPLETTERS_does_nothing_without_LOCALE(x):
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _natsort_key(s, None, ns.UG | ns.I) == _natsort_key(s, None, ns.I)
コード例 #46
0
def test__natsort_key_with_LOWERCASEFIRST_inverts_text_case(x):
    assume(len(x) <= 10)
    assume(not any(type(y) == float and isnan(y) for y in x))
    s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
    assert _natsort_key(s, None, ns.LOWERCASEFIRST) == tuple(_number_extracter(s.swapcase(), _int_nosign_re, *int_nosafe_nolocale_nogroup))
コード例 #47
0
def test_fast_float_with_key_applies_to_string(x):
    assume(not is_float(x))
    assume(bool(x))
    assert fast_float(x, key=len) == len(x)
コード例 #48
0
def test_grouper_returns_letters_with_lowercase_transform_of_letter(x):
    assume(type(fast_float(x)) is not float)
    assert grouper(x, (fast_float, isfloat)) == ''.join(
        chain.from_iterable([low(y), y] for y in x))
コード例 #49
0
def test_fast_float_leaves_float_asis(x):
    assume(not isnan(x))  # But inf is included
    assert fast_float(x) == x
コード例 #50
0
def test_grouper_returns_float_string_as_float(x):
    assume(not isnan(x))
    assert grouper(repr(x), (fast_float, isfloat)) == x
コード例 #51
0
def test_fast_float_leaves_string_as_is(x):
    assume(not is_float(x))
    assert fast_float(x) == x
コード例 #52
0
def test_locale_convert_transforms_float_string_to_float(x):
    assume(not isnan(x))
    load_locale('en_US')
    assert locale_convert(repr(x), (fast_float, isfloat), False) == x
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #53
0
def test_range_check_returns_range_as_is_but_with_floats_if_first_is_less_than_second2(x, y):
    assume(x < y)
    assert range_check(x, y) == (x, y)
コード例 #54
0
def test_locale_convert_transforms_nonfloat_string_to_strxfrm_string(x):
    assume(type(fast_float(x)) is not float)
    load_locale('en_US')
    strxfrm = get_strxfrm()
    assert locale_convert(x, (fast_float, isfloat), False) == strxfrm(x)
    locale.setlocale(locale.LC_NUMERIC, str(''))
コード例 #55
0
def test_check_filter_converts_filter_numbers_to_floats_if_filter_is_valid(x, y):
    assume(all(float(i) < float(j) for i, j in zip(x, y)))
    assert check_filter(list(zip(x, y))) == [(float(i), float(j)) for i, j in zip(x, y)]
コード例 #56
0
def test_parse_number_function_makes_function_that_returns_tuple(x):
    assume(not isnan(x))
    assert _parse_number_function(0, '')(x) == ('', x)
コード例 #57
0
def test_keep_entry_range_returns_True_if_any_portion_of_input_is_between_any_range_bounds(x):
    s = ''.join(map(py23_str, x))
    assume(any((1 < int(i) < 20) or (88 < int(i) < 90) for i in re.findall(r'\d+', s) if re.match(r'\d+$', i)))
    assert keep_entry_range(s, [1, 88], [20, 90], int, re.compile(r'\d+'))
コード例 #58
0
def test_parse_number_function_with_PATH_makes_function_that_returns_nested_tuple(x):
    assume(not isnan(x))
    assert _parse_number_function(ns.PATH, '')(x) == (('', x), )
コード例 #59
0
def test_exclude_entry_returns_False_if_exlcude_parameters_are_in_input(x):
    s = ''.join(map(py23_str, x))
    assume(any(int(i) in (23, 45, 87) for i in re.findall(r'\d+', s) if re.match(r'\d+$', i)))
    assert not exclude_entry(s, [23, 45, 87], int, re.compile(r'\d+'))
コード例 #60
0
ファイル: test_main.py プロジェクト: InSertCod3/natsort
def test_check_filter_raises_ValueError_if_filter_is_invalid(x, y):
    assume(any(i >= j for i, j in zip(x, y)))
    with raises(ValueError) as err:
        check_filter(list(zip(x, y)))
    assert str(err.value) == 'Error in --filter: low >= high'