summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth M Morton <seth.m.morton@gmail.com>2016-05-05 16:46:35 -0700
committerSeth M Morton <seth.m.morton@gmail.com>2016-05-05 16:46:35 -0700
commit06c917cf795fd55f188238afbe24ffdb9c215309 (patch)
treec2fdc6abf55761af297bbdf0c4e4ab4e63fa1307
parentc099dec56ff22b262489beebfb46941d586e121c (diff)
downloadnatsort-06c917cf795fd55f188238afbe24ffdb9c215309.tar.gz
Removed locale_help.py.
The remaining function, locale_convert_function, was replaced by get_strxfrm from natsort.compat.locale.
-rw-r--r--natsort/compat/locale.py7
-rw-r--r--natsort/locale_help.py29
-rw-r--r--natsort/utils.py4
-rw-r--r--test_natsort/compat/locale.py14
-rw-r--r--test_natsort/slow_splitters.py1
-rw-r--r--test_natsort/test_locale_help.py45
-rw-r--r--test_natsort/test_natsort_keygen.py6
-rw-r--r--test_natsort/test_post_split_function.py14
8 files changed, 17 insertions, 103 deletions
diff --git a/natsort/compat/locale.py b/natsort/compat/locale.py
index 6989710..e199aaf 100644
--- a/natsort/compat/locale.py
+++ b/natsort/compat/locale.py
@@ -16,7 +16,6 @@ try:
import PyICU
from locale import getlocale
- use_pyicu = True
null_string = b''
# If using PyICU, get the locale from the current global locale,
@@ -26,7 +25,7 @@ try:
except TypeError: # pragma: no cover
return PyICU.Locale()
- def get_pyicu_transform():
+ def get_strxfrm():
return PyICU.Collator.createInstance(get_icu_locale()).getSortKey
def get_thousands_sep():
@@ -49,7 +48,9 @@ except ImportError:
else:
from locale import strxfrm
null_string = ''
- use_pyicu = False
+
+ def get_strxfrm():
+ return strxfrm
def get_thousands_sep():
return locale.localeconv()['thousands_sep']
diff --git a/natsort/locale_help.py b/natsort/locale_help.py
deleted file mode 100644
index 48907cf..0000000
--- a/natsort/locale_help.py
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- coding: utf-8 -*-
-"""\
-This module is intended to help combine some locale functions
-together for natsort consumption. It also accounts for Python2
-and Python3 differences.
-"""
-from __future__ import (
- print_function,
- division,
- unicode_literals,
- absolute_import
-)
-
-# Local imports.
-from natsort.compat.locale import use_pyicu
-if use_pyicu:
- from natsort.compat.locale import get_pyicu_transform
-else:
- from natsort.compat.locale import strxfrm
-
-
-def locale_convert_function():
- """
- Return a function that will use the appropriate locale tranformation.
- """
- if use_pyicu:
- return get_pyicu_transform()
- else:
- return strxfrm
diff --git a/natsort/utils.py b/natsort/utils.py
index 5157591..98e6ea1 100644
--- a/natsort/utils.py
+++ b/natsort/utils.py
@@ -23,9 +23,9 @@ from operator import methodcaller
# Local imports.
from natsort.ns_enum import ns
from natsort.unicode_numbers import digits, numeric
-from natsort.locale_help import locale_convert_function
from natsort.compat.pathlib import PurePath, has_pathlib
from natsort.compat.locale import (
+ get_strxfrm,
get_thousands_sep,
get_decimal_point,
)
@@ -265,7 +265,7 @@ def _post_split_function(alg):
if group_letters:
func_chain.append(_groupletters)
if use_locale:
- func_chain.append(locale_convert_function())
+ func_chain.append(get_strxfrm())
kwargs = {'key': chain_functions(func_chain)} if func_chain else {}
# Return the correct chained functions.
diff --git a/test_natsort/compat/locale.py b/test_natsort/compat/locale.py
index d1b07a2..e515f94 100644
--- a/test_natsort/compat/locale.py
+++ b/test_natsort/compat/locale.py
@@ -10,7 +10,6 @@ from __future__ import (
import locale
# Local imports
-from natsort.locale_help import use_pyicu
from natsort.compat.py23 import py23_str, py23_unichr, py23_range
@@ -28,19 +27,6 @@ try:
except locale.Error:
has_locale_de_DE = False
-# Make a function that will return the appropriate
-# strxfrm for the current locale.
-if use_pyicu:
- from natsort.locale_help import get_pyicu_transform
-
- def get_strxfrm():
- return get_pyicu_transform()
-else:
- from natsort.locale_help import strxfrm
-
- def get_strxfrm():
- return strxfrm
-
# Depending on the python version, use lower or casefold
# to make a string lowercase.
try:
diff --git a/test_natsort/slow_splitters.py b/test_natsort/slow_splitters.py
index 5ed5e62..b597e10 100644
--- a/test_natsort/slow_splitters.py
+++ b/test_natsort/slow_splitters.py
@@ -7,7 +7,6 @@ import collections
import itertools
import functools
from natsort.compat.py23 import PY_VERSION, py23_zip
-# from natsort.compat.py23 import PY_VERSION, py23_zip, py23_map
if PY_VERSION >= 3.0:
long = int
diff --git a/test_natsort/test_locale_help.py b/test_natsort/test_locale_help.py
deleted file mode 100644
index fc89776..0000000
--- a/test_natsort/test_locale_help.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- coding: utf-8 -*-
-"""\
-Test the locale help module module.
-"""
-from __future__ import unicode_literals
-
-import locale
-import pytest
-from natsort.compat.fake_fastnumbers import fast_float
-from natsort.locale_help import locale_convert_function
-from compat.locale import (
- load_locale,
- get_strxfrm,
- bad_uni_chars,
-)
-from compat.hypothesis import (
- assume,
- given,
- text,
- use_hypothesis,
-)
-
-
-# Each test has an "example" version for demonstrative purposes,
-# and a test that uses the hypothesis module.
-
-
-def test_locale_convert_transforms_string_to_strxfrm_string_example():
- load_locale('en_US')
- strxfrm = get_strxfrm()
- assert locale_convert_function()('45,8') == strxfrm('45,8')
- assert locale_convert_function()('hello') == strxfrm('hello')
- locale.setlocale(locale.LC_NUMERIC, str(''))
-
-
-@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
-@given(text())
-def test_locale_convert_transforms_string_to_strxfrm_string(x):
- assume(bool(x))
- assume(type(fast_float(x)) is not float)
- assume(not any(i in bad_uni_chars for i in x))
- load_locale('en_US')
- strxfrm = get_strxfrm()
- assert locale_convert_function()(x) == strxfrm(x)
- locale.setlocale(locale.LC_NUMERIC, str(''))
diff --git a/test_natsort/test_natsort_keygen.py b/test_natsort/test_natsort_keygen.py
index 0ecc47d..3f48925 100644
--- a/test_natsort/test_natsort_keygen.py
+++ b/test_natsort/test_natsort_keygen.py
@@ -14,8 +14,10 @@ from natsort import (
ns,
)
from natsort.compat.py23 import PY_VERSION
-from natsort.compat.locale import null_string
-from compat.locale import get_strxfrm
+from natsort.compat.locale import (
+ null_string,
+ get_strxfrm,
+)
from compat.mock import patch
INPUT = ['6A-5.034e+1', '/Folder (1)/Foo', 56.7]
diff --git a/test_natsort/test_post_split_function.py b/test_natsort/test_post_split_function.py
index 47388d0..a0c4585 100644
--- a/test_natsort/test_post_split_function.py
+++ b/test_natsort/test_post_split_function.py
@@ -8,8 +8,8 @@ from natsort.utils import (
_post_split_function,
_groupletters,
)
-from natsort.locale_help import locale_convert_function
from natsort.compat.py23 import py23_str
+from natsort.compat.locale import get_strxfrm
from natsort.compat.fastnumbers import (
fast_float,
fast_int,
@@ -77,7 +77,7 @@ def test_post_split_function_with_GROUPLETTERS_returns_fast_int_and_groupletters
def test_post_split_function_with_LOCALE_returns_fast_int_and_groupletters_example():
x = 'hello'
- assert _post_split_function(ns.LOCALE)(x) == fast_int(x, key=locale_convert_function())
+ assert _post_split_function(ns.LOCALE)(x) == fast_int(x, key=get_strxfrm())
@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
@@ -85,12 +85,12 @@ def test_post_split_function_with_LOCALE_returns_fast_int_and_groupletters_examp
def test_post_split_function_with_LOCALE_returns_fast_int_and_groupletters(x):
assume(x)
assume(not any(y in bad_uni_chars for y in x))
- assert _post_split_function(ns.LOCALE)(x) == fast_int(x, key=locale_convert_function())
+ assert _post_split_function(ns.LOCALE)(x) == fast_int(x, key=get_strxfrm())
def test_post_split_function_with_LOCALE_and_GROUPLETTERS_returns_fast_int_and_groupletters_and_locale_convert_example():
x = 'hello'
- assert _post_split_function(ns.GROUPLETTERS | ns.LOCALE)(x) == fast_int(x, key=lambda x: locale_convert_function()(_groupletters(x)))
+ assert _post_split_function(ns.GROUPLETTERS | ns.LOCALE)(x) == fast_int(x, key=lambda x: get_strxfrm()(_groupletters(x)))
@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
@@ -98,7 +98,7 @@ def test_post_split_function_with_LOCALE_and_GROUPLETTERS_returns_fast_int_and_g
def test_post_split_function_with_LOCALE_and_GROUPLETTERS_returns_fast_int_and_groupletters_and_locale_convert(x):
assume(x)
try:
- assert _post_split_function(ns.GROUPLETTERS | ns.LOCALE)(x) == fast_int(x, key=lambda x: locale_convert_function()(_groupletters(x)))
+ assert _post_split_function(ns.GROUPLETTERS | ns.LOCALE)(x) == fast_int(x, key=lambda x: get_strxfrm()(_groupletters(x)))
except ValueError as e: # handle broken locale lib on BSD.
if 'is not in range' not in str(e):
raise
@@ -106,7 +106,7 @@ def test_post_split_function_with_LOCALE_and_GROUPLETTERS_returns_fast_int_and_g
def test_post_split_function_with_LOCALE_and_DUMB_returns_fast_int_and_groupletters_and_locale_convert_example():
x = 'hello'
- assert _post_split_function(ns._DUMB | ns.LOCALE)(x) == fast_int(x, key=lambda x: locale_convert_function()(_groupletters(x)))
+ assert _post_split_function(ns._DUMB | ns.LOCALE)(x) == fast_int(x, key=lambda x: get_strxfrm()(_groupletters(x)))
@pytest.mark.skipif(not use_hypothesis, reason='requires python2.7 or greater')
@@ -114,7 +114,7 @@ def test_post_split_function_with_LOCALE_and_DUMB_returns_fast_int_and_grouplett
def test_post_split_function_with_LOCALE_and_DUMB_returns_fast_int_and_groupletters_and_locale_convert(x):
assume(x)
try:
- assert _post_split_function(ns._DUMB | ns.LOCALE)(x) == fast_int(x, key=lambda x: locale_convert_function()(_groupletters(x)))
+ assert _post_split_function(ns._DUMB | ns.LOCALE)(x) == fast_int(x, key=lambda x: get_strxfrm()(_groupletters(x)))
except ValueError as e: # handle broken locale lib on BSD.
if 'is not in range' not in str(e):
raise