From 0e72e8fac81f03953901f9c7e074637f706aab0a Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Thu, 7 Nov 2019 19:44:14 -0800 Subject: Add tests for new public method --- tests/test_regex.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') 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 -- cgit v1.2.1 From af9e242433a0df387ba0ae5b123f9f590aefbd46 Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Sat, 9 Nov 2019 12:51:20 -0800 Subject: Disabled hypothesis HealthCheck on certain tests For some reason, some tests are deemed "too slow" by hypothesis and cause test failure. --- tests/test_final_data_transform_factory.py | 3 ++- tests/test_parse_bytes_function.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/test_final_data_transform_factory.py b/tests/test_final_data_transform_factory.py index fb2eb25..e438f3c 100644 --- a/tests/test_final_data_transform_factory.py +++ b/tests/test_final_data_transform_factory.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pytest -from hypothesis import example, given +from hypothesis import HealthCheck, example, given, settings from hypothesis.strategies import floats, integers, text from natsort.compat.py23 import py23_str from natsort.ns_enum import NS_DUMB, ns @@ -11,6 +11,7 @@ from natsort.utils import final_data_transform_factory @pytest.mark.parametrize("alg", [ns.DEFAULT, ns.UNGROUPLETTERS, ns.LOCALE]) +@settings(suppress_health_check=[HealthCheck.too_slow]) @given(x=text(), y=floats(allow_nan=False, allow_infinity=False) | integers()) @pytest.mark.usefixtures("with_locale_en_us") def test_final_data_transform_factory_default(x, y, alg): diff --git a/tests/test_parse_bytes_function.py b/tests/test_parse_bytes_function.py index 49f54ae..94e00cb 100644 --- a/tests/test_parse_bytes_function.py +++ b/tests/test_parse_bytes_function.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pytest -from hypothesis import given +from hypothesis import HealthCheck, given, settings from hypothesis.strategies import binary from natsort.ns_enum import ns from natsort.utils import parse_bytes_factory @@ -19,7 +19,8 @@ from natsort.utils import parse_bytes_factory (ns.PATH | ns.IGNORECASE, lambda x: ((x.lower(),),)), ], ) +@settings(suppress_health_check=[HealthCheck.too_slow]) @given(x=binary()) -def test_parse_bytest_factory_makes_function_that_returns_tuple(x, alg, example_func): +def test_parse_bytes_factory_makes_function_that_returns_tuple(x, alg, example_func): parse_bytes_func = parse_bytes_factory(alg) assert parse_bytes_func(x) == example_func(x) -- cgit v1.2.1 From 43927833d1dd9491858bb46986668a5649dc3258 Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Sat, 9 Nov 2019 16:53:19 -0800 Subject: Revert "Disabled hypothesis HealthCheck on certain tests" This reverts commit af9e242433a0df387ba0ae5b123f9f590aefbd46. --- tests/test_final_data_transform_factory.py | 3 +-- tests/test_parse_bytes_function.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/test_final_data_transform_factory.py b/tests/test_final_data_transform_factory.py index e438f3c..fb2eb25 100644 --- a/tests/test_final_data_transform_factory.py +++ b/tests/test_final_data_transform_factory.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pytest -from hypothesis import HealthCheck, example, given, settings +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 @@ -11,7 +11,6 @@ from natsort.utils import final_data_transform_factory @pytest.mark.parametrize("alg", [ns.DEFAULT, ns.UNGROUPLETTERS, ns.LOCALE]) -@settings(suppress_health_check=[HealthCheck.too_slow]) @given(x=text(), y=floats(allow_nan=False, allow_infinity=False) | integers()) @pytest.mark.usefixtures("with_locale_en_us") def test_final_data_transform_factory_default(x, y, alg): diff --git a/tests/test_parse_bytes_function.py b/tests/test_parse_bytes_function.py index 94e00cb..49f54ae 100644 --- a/tests/test_parse_bytes_function.py +++ b/tests/test_parse_bytes_function.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals import pytest -from hypothesis import HealthCheck, given, settings +from hypothesis import given from hypothesis.strategies import binary from natsort.ns_enum import ns from natsort.utils import parse_bytes_factory @@ -19,8 +19,7 @@ from natsort.utils import parse_bytes_factory (ns.PATH | ns.IGNORECASE, lambda x: ((x.lower(),),)), ], ) -@settings(suppress_health_check=[HealthCheck.too_slow]) @given(x=binary()) -def test_parse_bytes_factory_makes_function_that_returns_tuple(x, alg, example_func): +def test_parse_bytest_factory_makes_function_that_returns_tuple(x, alg, example_func): parse_bytes_func = parse_bytes_factory(alg) assert parse_bytes_func(x) == example_func(x) -- cgit v1.2.1 From a2bad79c65f9d4c7cb4ea35f4e49dd29abbfd0a1 Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Sat, 9 Nov 2019 16:59:55 -0800 Subject: Disable too slow hypothesis health checks globally --- tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') 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: -- cgit v1.2.1