def test_sep_inserter_does_nothing_if_no_numbers_example(): assert list(_sep_inserter(iter(['a', 'b', 'c']), '')) == ['a', 'b', 'c'] assert list(_sep_inserter(iter(['a']), '')) == ['a'] def test_sep_inserter_does_nothing_if_only_one_number_example(): assert list(_sep_inserter(iter(['a', 5]), '')) == ['a', 5] def test_sep_inserter_inserts_separator_string_between_two_numbers_example(): assert list(_sep_inserter(iter([5, 9]), '')) == ['', 5, '', 9] assert list(_sep_inserter(iter([5, 9]), null_string)) == [null_string, 5, null_string, 9] @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(elements=text() | integers())) def test_sep_inserter_inserts_separator_between_two_numbers(x): assume(bool(x)) assert list(_sep_inserter(iter(x), '')) == list(add_leading_space_if_first_is_num(sep_inserter(x, ''), '')) def test_path_splitter_splits_path_string_by_separator_example(): z = '/this/is/a/path' assert tuple(_path_splitter(z)) == tuple(pathlib.Path(z).parts) z = pathlib.Path('/this/is/a/path') assert tuple(_path_splitter(z)) == tuple(pathlib.Path(z).parts) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(sampled_from(string.ascii_letters), min_size=2)) def test_path_splitter_splits_path_string_by_separator(x):
assert _pre_split_function(ns.IGNORECASE | ns.LOWERCASEFIRST)(x) == x.swapcase().casefold() else: assert _pre_split_function(ns.IGNORECASE | ns.LOWERCASEFIRST)(x) == x.swapcase().lower() def test_pre_split_function_removes_thousands_separator_with_LOCALE_example(): load_locale('en_US') x = '12,543,642,642.534,534,980' # Without FLOAT it does not account for decimal. assert _pre_split_function(ns.LOCALE)(x) == '12543642642.534534980' x = '12,543,642,642.534,534,980' # LOCALEALPHA doesn't do anything... need LOCALENUM assert _pre_split_function(ns.LOCALEALPHA)(x) == '12,543,642,642.534,534,980' locale.setlocale(locale.LC_ALL, str('')) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(elements=integers(), min_size=4, max_size=20)) def test_pre_split_function_removes_thousands_separator_with_LOCALE(x): load_locale('en_US') t = ''.join(map(methodcaller('rstrip', 'lL'), map(str, map(abs, x)))) # Remove negative signs trailing L s = '' for i, y in enumerate(reversed(t), 1): s = y + s if i % 3 == 0 and i != len(t): s = ',' + s assert _pre_split_function(ns.LOCALE)(s) == t locale.setlocale(locale.LC_ALL, str('')) def test_pre_split_function_removes_thousands_separator_and_is_float_aware_with_LOCALE_and_FLOAT_example(): x = '12,543,642,642.534,534,980' assert _pre_split_function(ns.LOCALE | ns.FLOAT)(x) == '12543642642.534,534980'
def test_py3_safe_does_nothing_if_only_one_number_example(): assert _py3_safe(['a', 5], False, isint) == ['a', 5] def test_py3_safe_inserts_empty_string_between_two_numbers_example(): assert _py3_safe([5, 9], False, isint) == [5, '', 9] def test_py3_safe_with_use_locale_inserts_null_string_between_two_numbers_example( ): assert _py3_safe([5, 9], True, isint) == [5, null_string, 9] @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(elements=text() | integers())) def test_py3_safe_inserts_empty_string_between_two_numbers(x): assume(bool(x)) assert _py3_safe(x, False, isint) == sep_inserter(x, (int, long), '') def test_path_splitter_splits_path_string_by_separator_example(): z = '/this/is/a/path' assert _path_splitter(z) == list(pathlib.Path(z).parts) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(sampled_from(string.ascii_letters), min_size=2)) def test_path_splitter_splits_path_string_by_separator(x): assume(all(x)) z = py23_str(pathlib.Path(*x))
@given(floats() | integers()) def test__natsort_key_with_numeric_input_takes_number_path(x): assume(not isnan(x)) assert _natsort_key(x, None, string_func, bytes_func, num_func) == num_func(x) @pytest.mark.skipif(PY_VERSION < 3, reason='only valid on python3') @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(binary()) def test__natsort_key_with_bytes_input_takes_bytes_path(x): assume(x) assert _natsort_key(x, None, string_func, bytes_func, num_func) == bytes_func(x) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(elements=floats() | text() | integers(), min_size=1, max_size=10)) def test__natsort_key_with_text_input_takes_string_path(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, string_func, bytes_func, num_func) == string_func(s) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(lists(elements=text(), min_size=1, max_size=10)) def test__natsort_key_with_nested_input_takes_nested_path(x): assert _natsort_key(x, None, string_func, bytes_func, num_func) == tuple(string_func(s) for s in x) @pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater') @given(text()) def test__natsort_key_with_key_argument_applies_key_before_processing(x):