diff options
author | Seth Morton <seth.m.morton@gmail.com> | 2019-11-09 17:15:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-09 17:15:33 -0800 |
commit | 6ee7db9c6042ee286c9fc07475a26a2a5a76515a (patch) | |
tree | 2325a3d97fb7fef710d3250455695efcf4e26c3e /tests | |
parent | 5e640c09c5b4a10b86e3419ca81c7fb81f27a9de (diff) | |
parent | a2bad79c65f9d4c7cb4ea35f4e49dd29abbfd0a1 (diff) | |
download | natsort-6ee7db9c6042ee286c9fc07475a26a2a5a76515a.tar.gz |
Merge pull request #102 from SethMMorton/document-units
This pull request adds an example of how to sort based on units, and also exposes
a new function that helps building custom functions easier.
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 |