diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2018-02-08 23:21:17 -0800 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2018-02-10 13:40:13 -0800 |
commit | 391547fbfb52b63509887547a544dba6c0119a39 (patch) | |
tree | 1e663553d9a1214c8e1760477e63f614e20b504a | |
parent | d432715ef68470a45561e14c9e3e194bef97e525 (diff) | |
download | natsort-391547fbfb52b63509887547a544dba6c0119a39.tar.gz |
Add tests for ns.NUMAFTER.
These tests verify that the option puts numbers after non-numbers.
-rw-r--r-- | test_natsort/test_natsorted.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/test_natsort/test_natsorted.py b/test_natsort/test_natsorted.py index fcbf75b..71ffbf6 100644 --- a/test_natsort/test_natsorted.py +++ b/test_natsort/test_natsorted.py @@ -82,8 +82,10 @@ def test_natsorted_returns_sorted_list_with_mixed_type_input_and_does_not_raise_ def test_natsorted_with_mixed_input_returns_sorted_results_without_error(): a = ['0', 'Á', '2', 'Z'] assert natsorted(a) == ['0', '2', 'Á', 'Z'] + assert natsorted(a, alg=ns.NUMAFTER) == ['Á', 'Z', '0', '2'] a = ['2', 'ä', 'b', 1.5, 3] assert natsorted(a) == [1.5, '2', 3, 'ä', 'b'] + assert natsorted(a, alg=ns.NUMAFTER) == ['ä', 'b', 1.5, '2', 3] def test_natsorted_with_nan_input_returns_sorted_results_with_nan_last_with_NANLAST(): @@ -243,8 +245,10 @@ def test_natsorted_with_LOCALE_and_mixed_input_returns_sorted_results_without_er load_locale('en_US') a = ['0', 'Á', '2', 'Z'] assert natsorted(a, alg=ns.LOCALE) == ['0', '2', 'Á', 'Z'] + assert natsorted(a, alg=ns.LOCALE | ns.NUMAFTER) == ['Á', 'Z', '0', '2'] a = ['2', 'ä', 'b', 1.5, 3] assert natsorted(a, alg=ns.LOCALE) == [1.5, '2', 3, 'ä', 'b'] + assert natsorted(a, alg=ns.LOCALE | ns.NUMAFTER) == ['ä', 'b', 1.5, '2', 3] locale.setlocale(locale.LC_ALL, str('')) @@ -252,8 +256,10 @@ def test_natsorted_with_LOCALE_and_UNGROUPLETTERS_and_mixed_input_returns_sorted load_locale('en_US') a = ['0', 'Á', '2', 'Z'] assert natsorted(a, alg=ns.LOCALE | ns.UNGROUPLETTERS) == ['0', '2', 'Á', 'Z'] + assert natsorted(a, alg=ns.LOCALE | ns.UNGROUPLETTERS | ns.NUMAFTER) == ['Á', 'Z', '0', '2'] a = ['2', 'ä', 'b', 1.5, 3] assert natsorted(a, alg=ns.LOCALE | ns.UNGROUPLETTERS) == [1.5, '2', 3, 'ä', 'b'] + assert natsorted(a, alg=ns.LOCALE | ns.UNGROUPLETTERS | ns.NUMAFTER) == ['ä', 'b', 1.5, '2', 3] locale.setlocale(locale.LC_ALL, str('')) @@ -261,6 +267,16 @@ def test_natsorted_with_PATH_and_LOCALE_and_UNGROUPLETTERS_and_mixed_input_retur load_locale('en_US') a = ['0', 'Á', '2', 'Z'] assert natsorted(a, alg=ns.PATH | ns.LOCALE | ns.UNGROUPLETTERS) == ['0', '2', 'Á', 'Z'] + assert natsorted(a, alg=ns.PATH | ns.LOCALE | ns.UNGROUPLETTERS | ns.NUMAFTER) == ['Á', 'Z', '0', '2'] a = ['2', 'ä', 'b', 1.5, 3] assert natsorted(a, alg=ns.PATH | ns.LOCALE | ns.UNGROUPLETTERS) == [1.5, '2', 3, 'ä', 'b'] + assert natsorted(a, alg=ns.PATH | ns.LOCALE | ns.UNGROUPLETTERS | ns.NUMAFTER) == ['ä', 'b', 1.5, '2', 3] locale.setlocale(locale.LC_ALL, str('')) + + +def test_natsorted_sorts_an_odd_collection_of_string(): + a = ['Corn', 'apple', 'Banana', '73', 'Apple', '5039', 'corn', '~~~~~~', 'banana'] + assert natsorted(a) == ['73', '5039', 'Apple', 'Banana', 'Corn', + 'apple', 'banana', 'corn', '~~~~~~'] + assert natsorted(a, alg=ns.NUMAFTER) == ['Apple', 'Banana', 'Corn', + 'apple', 'banana', 'corn', '~~~~~~', '73', '5039'] |