summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2016-05-02 23:32:37 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2016-05-02 23:32:37 -0700
commitba0e027b0c0251f7f7f394cbf80de13851394360 (patch)
treef4e7b6eea26e68f4aff547c07a76d838e0421fc8
parent81d09ffc518a39f9ae524202671d8077679c897d (diff)
downloadnatsort-ba0e027b0c0251f7f7f394cbf80de13851394360.tar.gz
Fixed Python2/3 incompatibility bugs.
-rw-r--r--test_natsort/test_utils.py33
1 files changed, 18 insertions, 15 deletions
diff --git a/test_natsort/test_utils.py b/test_natsort/test_utils.py
index 737b3a7..9e20c44 100644
--- a/test_natsort/test_utils.py
+++ b/test_natsort/test_utils.py
@@ -623,10 +623,10 @@ def test_parse_string_function_selects_pre_function_value_if_not_dumb():
def tuple2(x, orig):
"""Make the input a tuple."""
return (orig[0], tuple(x))
- assert _parse_string_function(0, '', _int_nosign_re.split, str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
- assert _parse_string_function(ns._DUMB, '', _int_nosign_re.split, str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
- assert _parse_string_function(ns.LOCALE, '', _int_nosign_re.split, str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
- assert _parse_string_function(ns.LOCALE | ns._DUMB, '', _int_nosign_re.split, str.upper, fast_float, tuple2)('a5+5.034e-1') == ('a', ('A', 5, '+', 5, '.', 34, 'E-', 1))
+ assert _parse_string_function(0, '', _int_nosign_re.split, py23_str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
+ assert _parse_string_function(ns._DUMB, '', _int_nosign_re.split, py23_str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
+ assert _parse_string_function(ns.LOCALE, '', _int_nosign_re.split, py23_str.upper, fast_float, tuple2)('a5+5.034e-1') == ('A', ('A', 5, '+', 5, '.', 34, 'E-', 1))
+ assert _parse_string_function(ns.LOCALE | ns._DUMB, '', _int_nosign_re.split, py23_str.upper, fast_float, tuple2)('a5+5.034e-1') == ('a', ('A', 5, '+', 5, '.', 34, 'E-', 1))
def test_parse_path_function_parses_string_as_path_then_as_string():
@@ -656,13 +656,14 @@ def test__natsort_key_with_numeric_input_and_PATH_returns_number_in_nested_tuple
assert _natsort_key(10, None, sfunc, bytes_func, num_func) == (('', 10),)
-def test__natsort_key_with_bytes_input_and_PATH_returns_number_in_nested_tuple():
- # It gracefully handles as_path for numeric input by putting an extra tuple around it
- # so it will sort against the other as_path results.
- sfunc = _parse_path_function(string_func)
- bytes_func = _parse_bytes_function(ns.PATH)
- num_func = _parse_number_function(ns.PATH, '')
- assert _natsort_key(b'/hello/world', None, sfunc, bytes_func, num_func) == ((b'/hello/world',),)
+if sys.version[0] == '3':
+ def test__natsort_key_with_bytes_input_and_PATH_returns_number_in_nested_tuple():
+ # It gracefully handles as_path for numeric input by putting an extra tuple around it
+ # so it will sort against the other as_path results.
+ sfunc = _parse_path_function(string_func)
+ bytes_func = _parse_bytes_function(ns.PATH)
+ num_func = _parse_number_function(ns.PATH, '')
+ assert _natsort_key(b'/hello/world', None, sfunc, bytes_func, num_func) == ((b'/hello/world',),)
def test__natsort_key_with_tuple_of_paths_and_PATH_returns_triply_nested_tuple():
@@ -684,10 +685,12 @@ def test__natsort_key_with_numeric_input_takes_number_path(x):
assert _natsort_key(x, None, string_func, bytes_func, num_func) == num_func(x)
-@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):
- assert _natsort_key(x, None, string_func, bytes_func, num_func) == bytes_func(x)
+if sys.version[0] == '3':
+ @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')