diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 21:29:21 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-20 21:29:21 -0400 |
commit | 65a0c99f558274b7d583ccc9c9d6ce7c1fc52ce9 (patch) | |
tree | aeefe41233bc426319e2ebaf8054642a73655539 /tests/test_argparse_completer.py | |
parent | c86f6c7ec9d8a852abb2cd2d5a10b8bc851fef8b (diff) | |
download | cmd2-git-65a0c99f558274b7d583ccc9c9d6ce7c1fc52ce9.tar.gz |
Fixed unit tests
Diffstat (limited to 'tests/test_argparse_completer.py')
-rw-r--r-- | tests/test_argparse_completer.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index d1e115d4..68a2320c 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -13,8 +13,8 @@ from cmd2 import with_argparser, Cmd2ArgumentParser, CompletionItem from cmd2.utils import StdSim, basic_complete from .conftest import run_cmd, complete_tester -# Lists used in our tests -static_int_choices_list = [-12, -1, -2, 0, 1, 2] +# Lists used in our tests (there is a mix of sorted and unsorted on purpose) +static_int_choices_list = [-1, 1, -2, 2, 0, -12] static_choices_list = ['static', 'choices', 'stop', 'here'] choices_from_function = ['choices', 'function', 'chatty', 'smith'] choices_from_method = ['choices', 'method', 'most', 'improved'] @@ -353,12 +353,14 @@ def test_autcomp_flag_completion(ac_app, command_and_args, text, completions): ('--function', 'ch', ['choices', 'chatty']), ('-m', '', choices_from_method), ('--method', 'm', ['method', 'most']), - ('-i', '', [str(i) for i in static_int_choices_list]), + ('-i', '', static_int_choices_list), ('--int', '1', ['1 ']), - ('--int', '-', ['-12', '-1', '-2']), - ('--int', '-1', ['-12', '-1']) + ('--int', '-', [-1, -2, -12]), + ('--int', '-1', [-1, -12]) ]) def test_autocomp_flag_choices_completion(ac_app, flag, text, completions): + import numbers + line = 'choices {} {}'.format(flag, text) endidx = len(line) begidx = endidx - len(text) @@ -369,7 +371,14 @@ def test_autocomp_flag_choices_completion(ac_app, flag, text, completions): else: assert first_match is None - assert ac_app.completion_matches == sorted(completions, key=ac_app.default_sort_key) + # Numbers will be sorted in ascending order and then converted to strings by AutoCompleter + if all(isinstance(x, numbers.Number) for x in completions): + completions.sort() + completions = [str(x) for x in completions] + else: + completions.sort(key=ac_app.default_sort_key) + + assert ac_app.completion_matches == completions @pytest.mark.parametrize('pos, text, completions', [ |