summaryrefslogtreecommitdiff
path: root/tests/test_input_string_transform_factory.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_input_string_transform_factory.py')
-rw-r--r--tests/test_input_string_transform_factory.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/tests/test_input_string_transform_factory.py b/tests/test_input_string_transform_factory.py
index 7d54afd..6a08318 100644
--- a/tests/test_input_string_transform_factory.py
+++ b/tests/test_input_string_transform_factory.py
@@ -1,14 +1,15 @@
# -*- coding: utf-8 -*-
"""These test the utils.py functions."""
+from typing import Callable
import pytest
from hypothesis import example, given
from hypothesis.strategies import integers, text
-from natsort.ns_enum import NS_DUMB, ns
+from natsort.ns_enum import NSType, NS_DUMB, ns
from natsort.utils import input_string_transform_factory
-def thousands_separated_int(n):
+def thousands_separated_int(n: str) -> str:
"""Insert thousands separators in an int."""
new_int = ""
for i, y in enumerate(reversed(n), 1):
@@ -20,7 +21,7 @@ def thousands_separated_int(n):
@given(text())
-def test_input_string_transform_factory_is_no_op_for_no_alg_options(x):
+def test_input_string_transform_factory_is_no_op_for_no_alg_options(x: str) -> None:
input_string_transform_func = input_string_transform_factory(ns.DEFAULT)
assert input_string_transform_func(x) is x
@@ -36,7 +37,9 @@ def test_input_string_transform_factory_is_no_op_for_no_alg_options(x):
],
)
@given(x=text())
-def test_input_string_transform_factory(x, alg, example_func):
+def test_input_string_transform_factory(
+ x: str, alg: NSType, example_func: Callable[[str], str]
+) -> None:
input_string_transform_func = input_string_transform_factory(alg)
assert input_string_transform_func(x) == example_func(x)
@@ -44,7 +47,7 @@ def test_input_string_transform_factory(x, alg, example_func):
@example(12543642642534980) # 12,543,642,642,534,980 => 12543642642534980
@given(x=integers(min_value=1000))
@pytest.mark.usefixtures("with_locale_en_us")
-def test_input_string_transform_factory_cleans_thousands(x):
+def test_input_string_transform_factory_cleans_thousands(x: int) -> None:
int_str = str(x).rstrip("lL")
thousands_int_str = thousands_separated_int(int_str)
assert thousands_int_str.replace(",", "") != thousands_int_str
@@ -69,7 +72,9 @@ def test_input_string_transform_factory_cleans_thousands(x):
],
)
@pytest.mark.usefixtures("with_locale_en_us")
-def test_input_string_transform_factory_handles_us_locale(x, expected):
+def test_input_string_transform_factory_handles_us_locale(
+ x: str, expected: str
+) -> None:
input_string_transform_func = input_string_transform_factory(ns.LOCALE)
assert input_string_transform_func(x) == expected
@@ -83,7 +88,9 @@ def test_input_string_transform_factory_handles_us_locale(x, expected):
],
)
@pytest.mark.usefixtures("with_locale_de_de")
-def test_input_string_transform_factory_handles_de_locale(x, expected):
+def test_input_string_transform_factory_handles_de_locale(
+ x: str, expected: str
+) -> None:
input_string_transform_func = input_string_transform_factory(ns.LOCALE)
assert input_string_transform_func(x) == expected
@@ -97,13 +104,15 @@ def test_input_string_transform_factory_handles_de_locale(x, expected):
],
)
@pytest.mark.usefixtures("with_locale_de_de")
-def test_input_string_transform_factory_handles_german_locale(alg, expected):
+def test_input_string_transform_factory_handles_german_locale(
+ alg: NSType, expected: str
+) -> None:
input_string_transform_func = input_string_transform_factory(alg)
assert input_string_transform_func("1543,753") == expected
@pytest.mark.usefixtures("with_locale_de_de")
-def test_input_string_transform_factory_does_nothing_with_non_num_input():
+def test_input_string_transform_factory_does_nothing_with_non_num_input() -> None:
input_string_transform_func = input_string_transform_factory(ns.LOCALE | ns.FLOAT)
expected = "154s,t53"
assert input_string_transform_func("154s,t53") == expected