summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2018-11-18 22:54:34 -0800
committerSeth Morton <seth.m.morton@gmail.com>2019-03-03 21:17:49 -0800
commit7d62eb6961ebcfc3d98333ebb9adb4917e0c2f4f (patch)
treeeac3efc8dee0352a456af705bf92d128a0a6cab0
parent6557767879f3ebfffb1e824dbfb82511441a648f (diff)
downloadnatsort-7d62eb6961ebcfc3d98333ebb9adb4917e0c2f4f.tar.gz
Remove compat.py23 compatibility layer
This resolves *most* of the remaining Python 2 compatibility code.
-rw-r--r--natsort/__init__.py6
-rw-r--r--natsort/__main__.py5
-rw-r--r--natsort/compat/py23.py56
-rw-r--r--natsort/natsort.py4
-rw-r--r--natsort/unicode_numbers.py3
-rw-r--r--natsort/unicode_numeric_hex.py6
-rw-r--r--natsort/utils.py31
-rw-r--r--tests/profile_natsorted.py6
-rw-r--r--tests/test_fake_fastnumbers.py6
-rw-r--r--tests/test_final_data_transform_factory.py5
-rw-r--r--tests/test_input_string_transform_factory.py13
-rw-r--r--tests/test_natsort_key.py8
-rw-r--r--tests/test_natsort_keygen.py5
-rw-r--r--tests/test_natsorted.py2
-rw-r--r--tests/test_natsorted_convenience.py13
-rw-r--r--tests/test_parse_string_function.py5
-rw-r--r--tests/test_string_component_transform_factory.py9
-rw-r--r--tests/test_unicode_numbers.py5
-rw-r--r--tests/test_utils.py20
19 files changed, 40 insertions, 168 deletions
diff --git a/natsort/__init__.py b/natsort/__init__.py
index 3b77982..aa126eb 100644
--- a/natsort/__init__.py
+++ b/natsort/__init__.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
-import sys
-
from natsort.natsort import (
as_ascii,
as_utf8,
@@ -19,9 +17,6 @@ from natsort.natsort import (
)
from natsort.utils import chain_functions
-if float(sys.version[:3]) < 3:
- from natsort.natsort import natcmp
-
__version__ = "6.0.0"
__all__ = [
@@ -35,7 +30,6 @@ __all__ = [
"index_realsorted",
"order_by_index",
"decoder",
- "natcmp",
"as_ascii",
"as_utf8",
"ns",
diff --git a/natsort/__main__.py b/natsort/__main__.py
index 26d5325..e2f3299 100644
--- a/natsort/__main__.py
+++ b/natsort/__main__.py
@@ -3,7 +3,6 @@
import sys
import natsort
-from natsort.compat.py23 import py23_str
from natsort.utils import regex_chooser
@@ -190,7 +189,7 @@ def check_filters(filters):
try:
return [range_check(f[0], f[1]) for f in filters]
except ValueError as err:
- raise ValueError("Error in --filter: " + py23_str(err))
+ raise ValueError("Error in --filter: " + str(err))
def keep_entry_range(entry, lows, highs, converter, regex):
@@ -309,6 +308,6 @@ if __name__ == "__main__":
try:
main()
except ValueError as a:
- sys.exit(py23_str(a))
+ sys.exit(str(a))
except KeyboardInterrupt:
sys.exit(1)
diff --git a/natsort/compat/py23.py b/natsort/compat/py23.py
deleted file mode 100644
index bac2781..0000000
--- a/natsort/compat/py23.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-Compatibility layer for Python 2 and Python 3.
-
-Probably could have used six...
-This file will light up most linters...
-"""
-
-import functools
-import sys
-
-# These functions are used to make the doctests compatible between
-# python2 and python3, and also provide uniform functionality between
-# the two versions. This code is pretty much lifted from the iPython
-# project's py3compat.py file. Credit to the iPython devs.
-
-# Numeric form of version
-PY_VERSION = float(sys.version[:3])
-NEWPY = PY_VERSION >= 3.3
-
-# Assume all strings are Unicode in Python 2
-py23_str = str if PY_VERSION >= 3 else unicode
-
-# Use the range iterator always
-py23_range = range if PY_VERSION >= 3 else xrange
-
-# Uniform base string type
-py23_basestring = str if PY_VERSION >= 3 else basestring
-
-# Iniform int type
-py23_int = (int,) if PY_VERSION >= 3 else (int, long)
-
-# unichr function
-py23_unichr = chr if PY_VERSION >= 3 else unichr
-
-# Proper lower-casing of letters.
-py23_lower = py23_str.casefold if NEWPY else py23_str.lower
-
-
-def _py23_cmp(a, b):
- return (a > b) - (a < b)
-
-
-py23_cmp = _py23_cmp if PY_VERSION >= 3 else cmp
-
-# zip as an iterator
-if PY_VERSION >= 3:
- py23_zip = zip
- py23_map = map
- py23_filter = filter
-else:
- import itertools
-
- py23_zip = itertools.izip
- py23_map = itertools.imap
- py23_filter = itertools.ifilter
diff --git a/natsort/natsort.py b/natsort/natsort.py
index 99b6a1a..9a988fb 100644
--- a/natsort/natsort.py
+++ b/natsort/natsort.py
@@ -6,13 +6,11 @@ natsort public API.
The majority of the "work" is defined in utils.py.
"""
-import sys
from functools import partial
from operator import itemgetter
import natsort.compat.locale
from natsort import utils
-from natsort.compat.py23 import py23_str
from natsort.ns_enum import NS_DUMB, ns
@@ -153,7 +151,7 @@ def natsort_keygen(key=None, alg=ns.DEFAULT):
ns.DEFAULT | alg
except TypeError:
msg = "natsort_keygen: 'alg' argument must be from the enum 'ns'"
- raise ValueError(msg + ", got {}".format(py23_str(alg)))
+ raise ValueError(msg + ", got {}".format(str(alg)))
# Add the NS_DUMB option if the locale library is broken.
if alg & ns.LOCALEALPHA and natsort.compat.locale.dumb_sort():
diff --git a/natsort/unicode_numbers.py b/natsort/unicode_numbers.py
index dd26065..7800fd2 100644
--- a/natsort/unicode_numbers.py
+++ b/natsort/unicode_numbers.py
@@ -5,7 +5,6 @@ Pre-determine the collection of unicode decimals, digits, and numerals.
import unicodedata
-from natsort.compat.py23 import py23_unichr
from natsort.unicode_numeric_hex import numeric_hex
# Convert each hex into the literal Unicode character.
@@ -15,7 +14,7 @@ from natsort.unicode_numeric_hex import numeric_hex
numeric_chars = []
for a in numeric_hex:
try:
- character = py23_unichr(a)
+ character = chr(a)
except ValueError: # pragma: no cover
break
if unicodedata.numeric(character, None) is None:
diff --git a/natsort/unicode_numeric_hex.py b/natsort/unicode_numeric_hex.py
index de28f3b..2465e76 100644
--- a/natsort/unicode_numeric_hex.py
+++ b/natsort/unicode_numeric_hex.py
@@ -1735,12 +1735,12 @@ numeric_hex = (
# Some code that can be used to create the above list of hex numbers.
if __name__ == "__main__":
import unicodedata
- from natsort.compat.py23 import py23_range, py23_unichr
+ from natsort.compat.py23 import range, chr
hex_chars = []
- for i in py23_range(0X110000):
+ for i in range(0X110000):
try:
- a = py23_unichr(i)
+ a = chr(i)
except ValueError:
break
if a in "0123456789":
diff --git a/natsort/utils.py b/natsort/utils.py
index d062da2..0feb509 100644
--- a/natsort/utils.py
+++ b/natsort/utils.py
@@ -48,19 +48,9 @@ from unicodedata import normalize
from natsort.compat.fastnumbers import fast_float, fast_int
from natsort.compat.locale import get_decimal_point, get_strxfrm, get_thousands_sep
-from natsort.compat.py23 import (
- NEWPY,
- PY_VERSION,
- py23_filter,
- py23_map,
- py23_str,
-)
from natsort.ns_enum import NS_DUMB, ns
from natsort.unicode_numbers import digits_no_decimals, numeric_no_decimals
-if PY_VERSION >= 3:
- long = int
-
class NumericalRegularExpressions(object):
"""
@@ -168,11 +158,7 @@ def _normalize_input_factory(alg):
"""
normalization_form = "NFKD" if alg & ns.COMPATIBILITYNORMALIZE else "NFD"
- wrapped = partial(normalize, normalization_form)
- if NEWPY:
- return wrapped
- else:
- return lambda x, _f=wrapped: _f(x) if isinstance(x, py23_str) else x
+ return partial(normalize, normalization_form)
def natsort_key(val, key, string_func, bytes_func, num_func):
@@ -382,8 +368,8 @@ def parse_string_factory(
x = normalize_input(x)
x, original = input_transform(x), original_func(x)
x = splitter(x) # Split string into components.
- x = py23_filter(None, x) # Remove empty strings.
- x = py23_map(component_transform, x) # Apply transform on components.
+ x = filter(None, x) # Remove empty strings.
+ x = map(component_transform, x) # Apply transform on components.
x = sep_inserter(x, sep) # Insert '' between numbers.
return final_transform(x, original) # Apply the final transform.
@@ -414,7 +400,7 @@ def parse_path_factory(str_split):
parse_string_factory
"""
- return lambda x: tuple(py23_map(str_split, path_splitter(x)))
+ return lambda x: tuple(map(str_split, path_splitter(x)))
def sep_inserter(iterable, sep):
@@ -438,7 +424,7 @@ def sep_inserter(iterable, sep):
# Get the first element. A StopIteration indicates an empty iterable.
# Since we are controlling the types of the input, 'type' is used
# instead of 'isinstance' for the small speed advantage it offers.
- types = (int, float, long)
+ types = (int, float)
first = next(iterable)
if type(first) in types:
yield sep
@@ -492,10 +478,7 @@ def input_string_transform_factory(alg):
function_chain.append(methodcaller("swapcase"))
if alg & ns.IGNORECASE:
- if NEWPY:
- function_chain.append(methodcaller("casefold"))
- else:
- function_chain.append(methodcaller("lower"))
+ function_chain.append(methodcaller("casefold"))
if alg & ns.LOCALENUM:
# Create a regular expression that will remove thousands separators.
@@ -629,7 +612,7 @@ def final_data_transform_factory(alg, sep, pre_sep):
return lambda split_val, val: tuple(split_val)
-lower_function = methodcaller("casefold" if NEWPY else "lower")
+lower_function = methodcaller("casefold")
# noinspection PyIncorrectDocstring
diff --git a/tests/profile_natsorted.py b/tests/profile_natsorted.py
index 71cbc9c..a2b1a5c 100644
--- a/tests/profile_natsorted.py
+++ b/tests/profile_natsorted.py
@@ -10,11 +10,9 @@ import sys
try:
from natsort import ns, natsort_keygen
- from natsort.compat.py23 import py23_range
except ImportError:
sys.path.insert(0, ".")
from natsort import ns, natsort_keygen
- from natsort.compat.py23 import py23_range
locale.setlocale(locale.LC_ALL, "en_US.UTF-8")
@@ -36,7 +34,7 @@ locale_key = natsort_keygen(alg=ns.LOCALE)
def prof_time_to_generate():
print("*** Generate Plain Key ***")
- for _ in py23_range(100000):
+ for _ in range(100000):
natsort_keygen()
@@ -45,7 +43,7 @@ cProfile.run("prof_time_to_generate()", sort="time")
def prof_parsing(a, msg, key=basic_key):
print(msg)
- for _ in py23_range(100000):
+ for _ in range(100000):
key(a)
diff --git a/tests/test_fake_fastnumbers.py b/tests/test_fake_fastnumbers.py
index a1a6be6..c75bb11 100644
--- a/tests/test_fake_fastnumbers.py
+++ b/tests/test_fake_fastnumbers.py
@@ -9,10 +9,6 @@ from math import isnan
from hypothesis import given
from hypothesis.strategies import floats, integers, text
from natsort.compat.fake_fastnumbers import fast_float, fast_int
-from natsort.compat.py23 import PY_VERSION
-
-if PY_VERSION >= 3:
- long = int
def is_float(x):
@@ -38,7 +34,7 @@ def is_int(x):
return x.is_integer()
except AttributeError:
try:
- long(x)
+ int(x)
except ValueError:
try:
unicodedata.digit(x)
diff --git a/tests/test_final_data_transform_factory.py b/tests/test_final_data_transform_factory.py
index c93cfb7..dc6e1db 100644
--- a/tests/test_final_data_transform_factory.py
+++ b/tests/test_final_data_transform_factory.py
@@ -4,7 +4,6 @@
import pytest
from hypothesis import example, given
from hypothesis.strategies import floats, integers, text
-from natsort.compat.py23 import py23_str
from natsort.ns_enum import NS_DUMB, ns
from natsort.utils import final_data_transform_factory
@@ -15,7 +14,7 @@ from natsort.utils import final_data_transform_factory
def test_final_data_transform_factory_default(x, y, alg):
final_data_transform_func = final_data_transform_factory(alg, "", "::")
value = (x, y)
- original_value = "".join(map(py23_str, value))
+ original_value = "".join(map(str, value))
result = final_data_transform_func(value, original_value)
assert result == value
@@ -38,7 +37,7 @@ def test_final_data_transform_factory_default(x, y, alg):
def test_final_data_transform_factory_ungroup_and_locale(x, y, alg, func):
final_data_transform_func = final_data_transform_factory(alg, "", "::")
value = (x, y)
- original_value = "".join(map(py23_str, value))
+ original_value = "".join(map(str, value))
result = final_data_transform_func(value, original_value)
if x:
expected = ((func(original_value[:1]),), value)
diff --git a/tests/test_input_string_transform_factory.py b/tests/test_input_string_transform_factory.py
index 63e91d8..27dd725 100644
--- a/tests/test_input_string_transform_factory.py
+++ b/tests/test_input_string_transform_factory.py
@@ -4,19 +4,10 @@
import pytest
from hypothesis import example, given
from hypothesis.strategies import integers, text
-from natsort.compat.py23 import NEWPY
from natsort.ns_enum import NS_DUMB, ns
from natsort.utils import input_string_transform_factory
-def lower(x):
- """Call the appropriate lower method for the Python version."""
- if NEWPY:
- return x.casefold()
- else:
- return x.lower()
-
-
def thousands_separated_int(n):
"""Insert thousands separators in an int."""
new_int = ""
@@ -37,11 +28,11 @@ def test_input_string_transform_factory_is_no_op_for_no_alg_options(x):
@pytest.mark.parametrize(
"alg, example_func",
[
- (ns.IGNORECASE, lower),
+ (ns.IGNORECASE, lambda x: x.casefold()),
(NS_DUMB, lambda x: x.swapcase()),
(ns.LOWERCASEFIRST, lambda x: x.swapcase()),
(NS_DUMB | ns.LOWERCASEFIRST, lambda x: x), # No-op
- (ns.IGNORECASE | ns.LOWERCASEFIRST, lambda x: lower(x.swapcase())),
+ (ns.IGNORECASE | ns.LOWERCASEFIRST, lambda x: x.swapcase().casefold()),
],
)
@given(x=text())
diff --git a/tests/test_natsort_key.py b/tests/test_natsort_key.py
index 3464a6d..6b56bb1 100644
--- a/tests/test_natsort_key.py
+++ b/tests/test_natsort_key.py
@@ -1,18 +1,13 @@
# -*- coding: utf-8 -*-
"""These test the utils.py functions."""
-import pytest
from hypothesis import given
from hypothesis.strategies import binary, floats, integers, lists, text
-from natsort.compat.py23 import PY_VERSION, py23_str
from natsort.utils import natsort_key
-if PY_VERSION >= 3:
- long = int
-
def str_func(x):
- if isinstance(x, py23_str):
+ if isinstance(x, str):
return x
else:
raise TypeError("Not a str!")
@@ -27,7 +22,6 @@ def test_natsort_key_with_numeric_input_takes_number_path(x):
assert natsort_key(x, None, str_func, fail, lambda y: y) is x
-@pytest.mark.skipif(PY_VERSION < 3, reason="only valid on python3")
@given(binary().filter(bool))
def test_natsort_key_with_bytes_input_takes_bytes_path(x):
assert natsort_key(x, None, str_func, lambda y: y, fail) is x
diff --git a/tests/test_natsort_keygen.py b/tests/test_natsort_keygen.py
index 19b516e..96c4710 100644
--- a/tests/test_natsort_keygen.py
+++ b/tests/test_natsort_keygen.py
@@ -9,7 +9,6 @@ import os
import pytest
from natsort import natsort_key, natsort_keygen, natsorted, ns
from natsort.compat.locale import get_strxfrm, null_string_locale
-from natsort.compat.py23 import PY_VERSION, py23_str
@pytest.fixture
@@ -73,7 +72,7 @@ def test_natsort_keygen_returns_natsort_key_that_parses_input(alg, expected):
ns.PATH | ns.GROUPLETTERS,
(
(("", 6, "aA--", 5, "..", 34, "ee++", 1),),
- ((2 * py23_str(os.sep),), ("fFoollddeerr ((", 1, "))"), ("fFoooo",)),
+ ((2 * os.sep,), ("fFoollddeerr ((", 1, "))"), ("fFoooo",)),
(("", 56.7),),
),
),
@@ -94,7 +93,6 @@ def test_natsort_keygen_handles_arbitrary_input(arbitrary_input, alg, expected):
(ns.PATH | ns.GROUPLETTERS, ((b"6A-5.034e+1",),)),
],
)
-@pytest.mark.skipif(PY_VERSION < 3.0, reason="special bytes handling only on Python3")
def test_natsort_keygen_handles_bytes_input(bytes_input, alg, expected):
ns_key = natsort_keygen(alg=alg)
assert ns_key(bytes_input) == expected
@@ -160,7 +158,6 @@ def test_natsort_keygen_with_locale(mocker, arbitrary_input, alg, expected, is_d
"alg, is_dumb",
[(ns.LOCALE, False), (ns.LOCALE, True), (ns.LOCALE | ns.CAPITALFIRST, False)],
)
-@pytest.mark.skipif(PY_VERSION < 3.0, reason="special bytes handling only on Python3")
@pytest.mark.usefixtures("with_locale_en_us")
def test_natsort_keygen_with_locale_bytes(mocker, bytes_input, alg, is_dumb):
expected = (b"6A-5.034e+1",)
diff --git a/tests/test_natsorted.py b/tests/test_natsorted.py
index f0940aa..3ae97a2 100644
--- a/tests/test_natsorted.py
+++ b/tests/test_natsorted.py
@@ -8,7 +8,6 @@ from operator import itemgetter
import pytest
from natsort import as_utf8, natsorted, ns
-from natsort.compat.py23 import PY_VERSION
from pytest import raises
@@ -100,7 +99,6 @@ def test_natsorted_handles_nan(alg, expected, slc):
assert natsorted(given, alg=alg)[slc] == expected[slc]
-@pytest.mark.skipif(PY_VERSION < 3.0, reason="error is only raised on Python 3")
def test_natsorted_with_mixed_bytes_and_str_input_raises_type_error():
with raises(TypeError, match="bytes"):
natsorted(["รค", b"b"])
diff --git a/tests/test_natsorted_convenience.py b/tests/test_natsorted_convenience.py
index 0e5b6c5..7a91556 100644
--- a/tests/test_natsorted_convenience.py
+++ b/tests/test_natsorted_convenience.py
@@ -20,7 +20,6 @@ from natsort import (
order_by_index,
realsorted,
)
-from natsort.compat.py23 import PY_VERSION
@pytest.fixture
@@ -44,15 +43,9 @@ def test_decoder_returns_function_that_can_decode_bytes_but_return_non_bytes_as_
int_obj = 14
assert func(b"bytes") == str_obj
assert func(int_obj) is int_obj # returns as-is, same object ID
- if PY_VERSION >= 3:
- assert (
- func(str_obj) is str_obj
- ) # same object returned on Python3 b/c only bytes has decode
- else:
- assert func(str_obj) is not str_obj
- assert (
- func(str_obj) == str_obj
- ) # not same object on Python2 because str can decode
+ assert (
+ func(str_obj) is str_obj
+ ) # same object returned b/c only bytes has decode
def test_as_ascii_converts_bytes_to_ascii():
diff --git a/tests/test_parse_string_function.py b/tests/test_parse_string_function.py
index 3151aa2..9084248 100644
--- a/tests/test_parse_string_function.py
+++ b/tests/test_parse_string_function.py
@@ -7,7 +7,6 @@ import pytest
from hypothesis import given
from hypothesis.strategies import floats, integers, lists, text
from natsort.compat.fastnumbers import fast_float
-from natsort.compat.py23 import py23_str
from natsort.ns_enum import NS_DUMB, ns
from natsort.utils import NumericalRegularExpressions as NumRegex
from natsort.utils import parse_string_factory
@@ -78,10 +77,10 @@ def test_parse_string_factory_invariance(x, parse_string_func, orig_func):
# What is relevant is that the form of the output matches the invariant
# that even elements are string and odd are numerical. That each component
# function is doing what it should is tested elsewhere.
- value = "".join(map(py23_str, x)) # Convert the input to a single string.
+ value = "".join(map(str, x)) # Convert the input to a single string.
result = parse_string_func(value)
result_types = list(map(type, result))
- expected_types = [py23_str if i % 2 == 0 else float for i in range(len(result))]
+ expected_types = [str if i % 2 == 0 else float for i in range(len(result))]
assert result_types == expected_types
# The result is in our CustomTuple.
diff --git a/tests/test_string_component_transform_factory.py b/tests/test_string_component_transform_factory.py
index 7ad745b..c48138f 100644
--- a/tests/test_string_component_transform_factory.py
+++ b/tests/test_string_component_transform_factory.py
@@ -8,7 +8,6 @@ from hypothesis import example, given
from hypothesis.strategies import floats, integers, text
from natsort.compat.fastnumbers import fast_float, fast_int
from natsort.compat.locale import get_strxfrm
-from natsort.compat.py23 import py23_range, py23_str, py23_unichr
from natsort.ns_enum import NS_DUMB, ns
from natsort.utils import groupletters, string_component_transform_factory
@@ -17,7 +16,7 @@ from natsort.utils import groupletters, string_component_transform_factory
# raised by strxfrm). Let's filter them out.
try:
bad_uni_chars = frozenset(
- py23_unichr(x) for x in py23_range(0X10fefd, 0X10ffff + 1)
+ chr(x) for x in range(0X10fefd, 0X10ffff + 1)
)
except ValueError:
# Narrow unicode build... no worries.
@@ -48,8 +47,8 @@ def no_null(x):
partial(fast_int, key=lambda x: get_strxfrm()(groupletters(x))),
),
(
- NS_DUMB | ns.LOCALE,
- partial(fast_int, key=lambda x: get_strxfrm()(groupletters(x))),
+ NS_DUMB | ns.LOCALE,
+ partial(fast_int, key=lambda x: get_strxfrm()(groupletters(x))),
),
(
ns.GROUPLETTERS | ns.LOCALE | ns.FLOAT | ns.NANLAST,
@@ -71,7 +70,7 @@ def no_null(x):
def test_string_component_transform_factory(x, alg, example_func):
string_component_transform_func = string_component_transform_factory(alg)
try:
- assert string_component_transform_func(py23_str(x)) == example_func(py23_str(x))
+ assert string_component_transform_func(str(x)) == example_func(str(x))
except ValueError as e: # handle broken locale lib on BSD.
if "is not in range" not in str(e):
raise
diff --git a/tests/test_unicode_numbers.py b/tests/test_unicode_numbers.py
index c2139f2..a8ee3c7 100644
--- a/tests/test_unicode_numbers.py
+++ b/tests/test_unicode_numbers.py
@@ -5,7 +5,6 @@ Test the Unicode numbers module.
import unicodedata
-from natsort.compat.py23 import py23_range, py23_unichr
from natsort.unicode_numbers import (
decimal_chars,
decimals,
@@ -39,9 +38,9 @@ def test_numeric_chars_contains_all_valid_unicode_numeric_and_digit_characters()
set_numeric_chars = set(numeric_chars)
set_digit_chars = set(digit_chars)
set_decimal_chars = set(decimal_chars)
- for i in py23_range(0X110000):
+ for i in range(0X110000):
try:
- a = py23_unichr(i)
+ a = chr(i)
except ValueError:
break
if a in "0123456789":
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 76d8e23..73d701b 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -11,12 +11,11 @@ import pytest
from hypothesis import given
from hypothesis.strategies import integers, lists, sampled_from, text
from natsort import utils
-from natsort.compat.py23 import py23_cmp, py23_int, py23_lower, py23_str
from natsort.ns_enum import ns
def test_do_decoding_decodes_bytes_string_to_unicode():
- assert type(utils.do_decoding(b"bytes", "ascii")) is py23_str
+ assert type(utils.do_decoding(b"bytes", "ascii")) is str
assert utils.do_decoding(b"bytes", "ascii") == "bytes"
assert utils.do_decoding(b"bytes", "ascii") == b"bytes".decode("ascii")
@@ -100,7 +99,7 @@ def test_groupletters_returns_letters_with_lowercase_transform_of_letter_example
@given(text().filter(bool))
def test_groupletters_returns_letters_with_lowercase_transform_of_letter(x):
assert utils.groupletters(x) == "".join(
- chain.from_iterable([py23_lower(y), y] for y in x)
+ chain.from_iterable([y.casefold(), y] for y in x)
)
@@ -124,8 +123,8 @@ def test_sep_inserter_inserts_separator_between_two_numbers(x):
result = list(utils.sep_inserter(iter(x), ""))
for i, pos in enumerate(result[1:-1], 1):
if pos == "":
- assert isinstance(result[i - 1], py23_int)
- assert isinstance(result[i + 1], py23_int)
+ assert isinstance(result[i - 1], int)
+ assert isinstance(result[i + 1], int)
def test_path_splitter_splits_path_string_by_separator_example():
@@ -138,7 +137,7 @@ def test_path_splitter_splits_path_string_by_separator_example():
@given(lists(sampled_from(string.ascii_letters), min_size=2).filter(all))
def test_path_splitter_splits_path_string_by_separator(x):
- z = py23_str(pathlib.Path(*x))
+ z = str(pathlib.Path(*x))
assert tuple(utils.path_splitter(z)) == tuple(pathlib.Path(z).parts)
@@ -150,16 +149,9 @@ def test_path_splitter_splits_path_string_by_separator_and_removes_extension_exa
@given(lists(sampled_from(string.ascii_letters), min_size=3).filter(all))
def test_path_splitter_splits_path_string_by_separator_and_removes_extension(x):
- z = py23_str(pathlib.Path(*x[:-2])) + "." + x[-1]
+ z = str(pathlib.Path(*x[:-2])) + "." + x[-1]
y = tuple(pathlib.Path(z).parts)
assert tuple(utils.path_splitter(z)) == y[:-1] + (
pathlib.Path(z).stem,
pathlib.Path(z).suffix,
)
-
-
-@given(integers())
-def test_py23_cmp(x):
- assert py23_cmp(x, x) == 0
- assert py23_cmp(x, x + 1) < 0
- assert py23_cmp(x, x - 1) > 0