diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 10 | ||||
-rw-r--r-- | tests/test_regex.py | 20 |
2 files changed, 30 insertions, 0 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 8a7412b..d584789 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,19 @@ Fixtures for pytest. import locale +import hypothesis import pytest +# This disables the "too slow" hypothesis heath check globally. +# For some reason it thinks that the text/binary generation is too +# slow then causes the tests to fail. +hypothesis.settings.register_profile( + "slow-tests", + suppress_health_check=[hypothesis.HealthCheck.too_slow], +) + + def load_locale(x): """Convenience to load a locale, trying ISO8859-1 first.""" try: diff --git a/tests/test_regex.py b/tests/test_regex.py index d3fe617..a6da62d 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import pytest +from natsort import ns, numeric_regex_chooser from natsort.utils import NumericalRegularExpressions as NumRegex @@ -98,3 +99,22 @@ labels = ["{}-{}".format(given, regex_names[regex]) for given, _, regex in regex def test_regex_splits_correctly(x, expected, regex): # noinspection PyUnresolvedReferences assert regex.split(x) == expected + + +@pytest.mark.parametrize( + "given, expected", + [ + (ns.INT, NumRegex.int_nosign()), + (ns.INT | ns.UNSIGNED, NumRegex.int_nosign()), + (ns.INT | ns.SIGNED, NumRegex.int_sign()), + (ns.INT | ns.NOEXP, NumRegex.int_nosign()), + (ns.FLOAT, NumRegex.float_nosign_exp()), + (ns.FLOAT | ns.UNSIGNED, NumRegex.float_nosign_exp()), + (ns.FLOAT | ns.SIGNED, NumRegex.float_sign_exp()), + (ns.FLOAT | ns.NOEXP, NumRegex.float_nosign_noexp()), + (ns.FLOAT | ns.SIGNED | ns.NOEXP, NumRegex.float_sign_noexp()), + (ns.FLOAT | ns.UNSIGNED | ns.NOEXP, NumRegex.float_nosign_noexp()), + ], +) +def test_regex_chooser(given, expected): + assert numeric_regex_chooser(given) == expected.pattern[1:-1] # remove parens |