本文整理汇总了Python中natsort.utils._number_extracter函数的典型用法代码示例。如果您正苦于以下问题:Python _number_extracter函数的具体用法?Python _number_extracter怎么用?Python _number_extracter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_number_extracter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__natsort_key_with_IGNORECASE_lowercases_text
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))
示例2: test__natsort_key_with_float_and_unsigned_splits_input_into_string_and_unsigned_float
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))
示例3: test__natsort_key_with_int_splits_input_into_string_and_unsigned_int
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))
示例4: test__natsort_key_with_LOCALE_transforms_floats_according_to_the_current_locale_and_strxfrms_strings
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(''))
示例5: test__natsort_key_with_float_and_signed_splits_input_into_string_and_signed_float_with_exponent
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))
示例6: test__natsort_key_with_tuple_input_returns_nested_tuples
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)
示例7: assume
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)
示例8: test_number_extracter_doubles_letters_with_lowercase_version_with_groupletters_for_float
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
示例9: test__natsort_key_with_tuple_input_but_itemgetter_key_returns_split_second_element
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
示例10: assume
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)
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
locale.setlocale(locale.LC_NUMERIC, str(''))
示例11: test_number_extracter_doubles_letters_with_lowercase_version_with_groupletters_for_int
def test_number_extracter_doubles_letters_with_lowercase_version_with_groupletters_for_int(x):
assume(len(x) <= 10)
try:
low = py23_str.casefold
except AttributeError:
low = py23_str.lower
s = ''.join(repr(y) if type(y) in (float, long, int) else y for y in x)
t = int_splitter(s, False, False, '')
t = [''.join([low(z) + z for z in y]) if type(y) not in (int, long) else y for y in t]
assert _number_extracter(s, _int_nosign_re, *int_nosafe_nolocale_group) == t
示例12: load_locale
def test_number_extracter_extracts_numbers_and_strxfrms_letter_doubled_strings_with_use_locale_and_groupletters_example():
load_locale('en_US')
if use_pyicu:
from natsort.locale_help import get_pyicu_transform
from locale import getlocale
strxfrm = get_pyicu_transform(getlocale())
else:
from natsort.locale_help import strxfrm
assert _number_extracter('A5+5.034E-1', _int_nosign_re, *int_nosafe_locale_group) == [strxfrm('aA'), 5, strxfrm('++'), 5, strxfrm('..'), 34, strxfrm('eE--'), 1]
locale.setlocale(locale.LC_NUMERIC, str(''))
示例13: test_number_extracter_extracts_numbers_and_strxfrms_strings_with_use_locale
def test_number_extracter_extracts_numbers_and_strxfrms_strings_with_use_locale(x):
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), False) for i, y in enumerate(t)]
assert _number_extracter(s, _int_nosign_re, *int_nosafe_locale_nogroup) == t
except OverflowError:
pass
locale.setlocale(locale.LC_NUMERIC, str(''))
示例14: test_number_extracter_extracts_numbers_and_strxfrms_strings_with_use_locale
def test_number_extracter_extracts_numbers_and_strxfrms_strings_with_use_locale():
locale.setlocale(locale.LC_NUMERIC, str('en_US.UTF-8'))
if use_pyicu:
from natsort.locale_help import get_pyicu_transform
from locale import getlocale
strxfrm = get_pyicu_transform(getlocale())
else:
from natsort.locale_help import strxfrm
assert _number_extracter('A5+5.034E-1', _int_nosign_re, *ittf) == [strxfrm('A'), 5, strxfrm('+'), 5, strxfrm('.'), 34, strxfrm('E-'), 1]
locale.setlocale(locale.LC_NUMERIC, str(''))
示例15: test__natsort_key_with_GROUPLETTERS_doubles_text_with_lowercase_letter_first
def test__natsort_key_with_GROUPLETTERS_doubles_text_with_lowercase_letter_first(x):
try:
low = py23_str.casefold
except AttributeError:
low = py23_str.lower
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, _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)