diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2018-08-25 20:02:23 -0700 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2018-08-25 20:02:55 -0700 |
commit | 77a1fbefc9a874af52c9e5d261d66d604f296ab5 (patch) | |
tree | e3281901541cce52bfe08383d18a5d8e2ec4782b | |
parent | 00b4b7d6ee809c4947995ad0291bddd9c2a18871 (diff) | |
download | natsort-77a1fbefc9a874af52c9e5d261d66d604f296ab5.tar.gz |
Refactor test_parse_bytes_function.py.
All tests have been consolidated into a single parameterized test.
-rw-r--r-- | test_natsort/test_parse_bytes_function.py | 56 |
1 files changed, 15 insertions, 41 deletions
diff --git a/test_natsort/test_parse_bytes_function.py b/test_natsort/test_parse_bytes_function.py index 33037d1..b7631b9 100644 --- a/test_natsort/test_parse_bytes_function.py +++ b/test_natsort/test_parse_bytes_function.py @@ -2,50 +2,24 @@ """These test the utils.py functions.""" from __future__ import unicode_literals +import pytest from hypothesis import given from hypothesis.strategies import binary from natsort.ns_enum import ns from natsort.utils import parse_bytes_factory -# Each test has an "example" version for demonstrative purposes, -# and a test that uses the hypothesis module. - -def test_parse_bytes_factory_makes_function_that_returns_tuple_example(): - assert parse_bytes_factory(0)(b"hello") == (b"hello",) - - -@given(binary()) -def test_parse_bytes_factory_makes_function_that_returns_tuple(x): - assert parse_bytes_factory(0)(x) == (x,) - - -def test_parse_bytes_factory_with_IGNORECASE_makes_function_that_returns_tuple_with_lowercase_example(): - assert parse_bytes_factory(ns.IGNORECASE)(b"HelLo") == (b"hello",) - - -@given(binary()) -def test_parse_bytes_factory_with_IGNORECASE_makes_function_that_returns_tuple_with_lowercase( - x -): - assert parse_bytes_factory(ns.IGNORECASE)(x) == (x.lower(),) - - -def test_parse_bytes_factory_with_PATH_makes_function_that_returns_nested_tuple_example(): - assert parse_bytes_factory(ns.PATH)(b"hello") == ((b"hello",),) - - -@given(binary()) -def test_parse_bytes_factory_with_PATH_makes_function_that_returns_nested_tuple(x): - assert parse_bytes_factory(ns.PATH)(x) == ((x,),) - - -def test_parse_bytes_factory_with_PATH_and_IGNORECASE_makes_function_that_returns_nested_tuple_with_lowercase_example(): - assert parse_bytes_factory(ns.PATH | ns.IGNORECASE)(b"HelLo") == ((b"hello",),) - - -@given(binary()) -def test_parse_bytes_factory_with_PATH_and_IGNORECASE_makes_function_that_returns_nested_tuple_with_lowercase( - x -): - assert parse_bytes_factory(ns.PATH | ns.IGNORECASE)(x) == ((x.lower(),),) +@pytest.mark.parametrize( + "alg, example_func", + [ + (0, lambda x: (x,)), + (ns.IGNORECASE, lambda x: (x.lower(),)), + # With PATH, it becomes a tested tuple. + (ns.PATH, lambda x: ((x,),)), + (ns.PATH | ns.IGNORECASE, lambda x: ((x.lower(),),)), + ], +) +@given(x=binary()) +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) |