summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2016-05-04 20:55:01 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2016-05-04 20:55:01 -0700
commitea41e7f72a3867f7ce7de27c72e9ed23d1688060 (patch)
treeb64b7cb66a2fccc93427f12ddfd035feef2df84d
parent22ad659ed844cbdd7d179b74acc7b25d135da73f (diff)
downloadnatsort-ea41e7f72a3867f7ce7de27c72e9ed23d1688060.tar.gz
Fixed PyICU TypeError.
With the LOCALE | CAPITALFIRST options there was a type mismatch between numbers and strings. This has been resolved by replacing "null_sep" with ''.
-rw-r--r--natsort/utils.py12
-rw-r--r--test_natsort/test_natsort_keygen.py2
-rw-r--r--test_natsort/test_parse_number_function.py13
-rw-r--r--test_natsort/test_post_string_parse_function.py3
4 files changed, 11 insertions, 19 deletions
diff --git a/natsort/utils.py b/natsort/utils.py
index c74d340..20eeeb4 100644
--- a/natsort/utils.py
+++ b/natsort/utils.py
@@ -33,7 +33,6 @@ from natsort.compat.py23 import (
py23_filter,
PY_VERSION,
)
-from natsort.compat.locale import use_pyicu
from natsort.compat.fastnumbers import (
fast_float,
fast_int,
@@ -116,6 +115,7 @@ def _natsort_key(val, key, string_func, bytes_func, num_func):
) for x in val)
# If that failed, it must be a number.
except TypeError:
+ print('num', num_func(val))
return num_func(val)
@@ -142,11 +142,10 @@ def _parse_number_function(alg, sep):
return (sep, nan_replace if val != val else val)
# Return the function, possibly wrapping in tuple if PATH is selected.
- null_sep = b'' if use_pyicu else ''
if alg & ns.PATH and alg & ns.UNGROUPLETTERS and alg & ns.LOCALE:
- return lambda x: (((null_sep,), func(x)),)
+ return lambda x: ((('',), func(x)),)
elif alg & ns.UNGROUPLETTERS and alg & ns.LOCALE:
- return lambda x: ((null_sep,), func(x))
+ return lambda x: (('',), func(x))
elif alg & ns.PATH:
return lambda x: (func(x),)
else:
@@ -265,8 +264,7 @@ def _post_string_parse_function(alg, sep):
def func(split_val,
val,
- f=(lambda x: x.swapcase()) if swap else lambda x: x,
- null_sep=b'' if use_pyicu else ''):
+ f=(lambda x: x.swapcase()) if swap else lambda x: x):
"""
Return a tuple with the first character of the first element
of the return value as the first element, and the return value
@@ -277,7 +275,7 @@ def _post_string_parse_function(alg, sep):
if not split_val:
return ((), ())
elif split_val[0] == sep:
- return ((null_sep,), split_val)
+ return (('',), split_val)
else:
return ((f(val[0]),), split_val)
return func
diff --git a/test_natsort/test_natsort_keygen.py b/test_natsort/test_natsort_keygen.py
index 60b139c..80c9319 100644
--- a/test_natsort/test_natsort_keygen.py
+++ b/test_natsort/test_natsort_keygen.py
@@ -84,7 +84,7 @@ def test_natsort_keygen_splits_input_with_locale():
def test_natsort_keygen_splits_input_with_locale_and_capitalfirst():
strxfrm = get_strxfrm()
with patch('natsort.compat.locale.dumb_sort', return_value=False):
- assert natsort_keygen(alg=ns.L | ns.C)(INPUT) == (((null_string,), (null_string, 6, strxfrm('A-'), 5, strxfrm('.'), 34, strxfrm('e+'), 1)), (('/',), (strxfrm('/Folder ('), 1, strxfrm(')/Foo'))), ((null_string,), (null_string, 56.7)))
+ assert natsort_keygen(alg=ns.L | ns.C)(INPUT) == ((('',), (null_string, 6, strxfrm('A-'), 5, strxfrm('.'), 34, strxfrm('e+'), 1)), (('/',), (strxfrm('/Folder ('), 1, strxfrm(')/Foo'))), (('',), (null_string, 56.7)))
if IS_PY3: assert natsort_keygen(alg=ns.L | ns.C)(b'6A-5.034e+1') == (b'6A-5.034e+1',)
diff --git a/test_natsort/test_parse_number_function.py b/test_natsort/test_parse_number_function.py
index 0023e66..4c8167b 100644
--- a/test_natsort/test_parse_number_function.py
+++ b/test_natsort/test_parse_number_function.py
@@ -6,7 +6,6 @@ import pytest
from math import isnan
from natsort.ns_enum import ns
from natsort.utils import _parse_number_function
-from natsort.compat.locale import use_pyicu
from compat.hypothesis import (
assume,
given,
@@ -45,26 +44,22 @@ def test_parse_number_function_with_PATH_makes_function_that_returns_nested_tupl
def test_parse_number_function_with_UNGROUPLETTERS_LOCALE_makes_function_that_returns_nested_tuple_example():
- null_sep = b'' if use_pyicu else ''
- assert _parse_number_function(ns.UNGROUPLETTERS | ns.LOCALE, '')(57) == ((null_sep,), ('', 57))
+ assert _parse_number_function(ns.UNGROUPLETTERS | ns.LOCALE, '')(57) == (('',), ('', 57))
@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
@given(floats() | integers())
def test_parse_number_function_with_UNGROUPLETTERS_LOCALE_makes_function_that_returns_nested_tuple(x):
assume(not isnan(x))
- null_sep = b'' if use_pyicu else ''
- assert _parse_number_function(ns.UNGROUPLETTERS | ns.LOCALE, '')(x) == ((null_sep,), ('', x))
+ assert _parse_number_function(ns.UNGROUPLETTERS | ns.LOCALE, '')(x) == (('',), ('', x))
def test_parse_number_function_with_PATH_UNGROUPLETTERS_LOCALE_makes_function_that_returns_nested_tuple_example():
- null_sep = b'' if use_pyicu else ''
- assert _parse_number_function(ns.PATH | ns.UNGROUPLETTERS | ns.LOCALE, '')(57) == (((null_sep,), ('', 57)),)
+ assert _parse_number_function(ns.PATH | ns.UNGROUPLETTERS | ns.LOCALE, '')(57) == ((('',), ('', 57)),)
@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
@given(floats() | integers())
def test_parse_number_function_with_PATH_UNGROUPLETTERS_LOCALE_makes_function_that_returns_nested_tuple(x):
assume(not isnan(x))
- null_sep = b'' if use_pyicu else ''
- assert _parse_number_function(ns.PATH | ns.UNGROUPLETTERS | ns.LOCALE, '')(x) == (((null_sep,), ('', x)),)
+ assert _parse_number_function(ns.PATH | ns.UNGROUPLETTERS | ns.LOCALE, '')(x) == ((('',), ('', x)),)
diff --git a/test_natsort/test_post_string_parse_function.py b/test_natsort/test_post_string_parse_function.py
index 26dd1e7..7e581f5 100644
--- a/test_natsort/test_post_string_parse_function.py
+++ b/test_natsort/test_post_string_parse_function.py
@@ -7,7 +7,6 @@ from math import isnan, isinf
from natsort.ns_enum import ns
from natsort.utils import _post_string_parse_function
from natsort.compat.py23 import py23_str
-from natsort.compat.locale import use_pyicu
from compat.hypothesis import (
assume,
given,
@@ -40,7 +39,7 @@ def test_post_string_parse_function_with_empty_tuple_returns_double_empty_tuple(
def test_post_string_parse_function_with_null_string_first_element_adds_empty_string_on_first_tuple_element():
- assert _post_string_parse_function(ns.LOCALE | ns.UNGROUPLETTERS, '')(('', 60), '') == ((b'',) if use_pyicu else ('',), ('', 60))
+ assert _post_string_parse_function(ns.LOCALE | ns.UNGROUPLETTERS, '')(('', 60), '') == (('',), ('', 60))
def test_post_string_parse_function_returns_first_element_in_first_tuple_element_example():