diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-08-19 14:45:28 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-08-19 15:50:24 -0400 |
| commit | 8ba05ef8bcdd53bdd54999cc9885ab310b766d9c (patch) | |
| tree | 4a683b34d41710f94e7f259580ceb0ff1f46cc4b /tests | |
| parent | df1925db8607b06079ba78d497701ca961b855ab (diff) | |
| download | cmd2-git-8ba05ef8bcdd53bdd54999cc9885ab310b766d9c.tar.gz | |
set command output now uses SimpleTable.
Tabled tab completion now includes divider row.
Tab completion results for aliases, macros, and Settables wrap long fields.
SimpleTable now accepts blank for the divider character. It is identical to passing None.
Removed --verbose flag from set command so the descriptions always show.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/conftest.py | 40 | ||||
| -rw-r--r-- | tests/test_argparse_completer.py | 24 | ||||
| -rwxr-xr-x | tests/test_cmd2.py | 47 | ||||
| -rw-r--r-- | tests/test_table_creator.py | 7 | ||||
| -rw-r--r-- | tests/transcripts/regex_set.txt | 31 |
5 files changed, 88 insertions, 61 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index a5c47d97..0829da2f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -104,29 +104,23 @@ SHORTCUTS_TXT = """Shortcuts for other commands: @@: _relative_run_script """ -# Output from the show command with default settings -SHOW_TXT = """allow_style: 'Terminal' -always_show_hint: False -debug: False -echo: False -editor: 'vim' -feedback_to_output: False -max_completion_items: 50 -quiet: False -timing: False -""" - -SHOW_LONG = """ -allow_style: 'Terminal' # Allow ANSI text style sequences in output (valid values: Terminal, Always, Never) -always_show_hint: False # Display tab completion hint even when completion suggestions print -debug: False # Show full traceback on exception -echo: False # Echo command issued into output -editor: 'vim' # Program used by 'edit' -feedback_to_output: False # Include nonessentials in '|', '>' results -max_completion_items: 50 # Maximum number of CompletionItems to display during tab completion -quiet: False # Don't print nonessential feedback -timing: False # Report execution times -""" +# Output from the set command +SET_TXT = ( + "Name Value Description \n" + "==================================================================================================================\n" + "allow_style Terminal Allow ANSI text style sequences in output (valid values: \n" + " Terminal, Always, Never) \n" + "always_show_hint False Display tab completion hint even when completion suggestions\n" + " print \n" + "debug False Show full traceback on exception \n" + "echo False Echo command issued into output \n" + "editor vim Program used by 'edit' \n" + "feedback_to_output False Include nonessentials in '|', '>' results \n" + "max_completion_items 50 Maximum number of CompletionItems to display during tab \n" + " completion \n" + "quiet False Don't print nonessential feedback \n" + "timing False Report execution times \n" +) def normalize(block): diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py index 6002a856..25a13157 100644 --- a/tests/test_argparse_completer.py +++ b/tests/test_argparse_completer.py @@ -725,10 +725,14 @@ def test_completion_items(ac_app, num_aliases, show_description): assert bool(ac_app.formatted_completions) == show_description if show_description: - # If show_description is True, the table will show both the alias name and result - first_result_line = normalize(ac_app.formatted_completions)[1] - assert 'fake_alias0' in first_result_line - assert 'help' in first_result_line + # If show_description is True, the table will show both the alias name and value + description_displayed = False + for line in ac_app.formatted_completions.splitlines(): + if 'fake_alias0' in line and 'help' in line: + description_displayed = True + break + + assert description_displayed def test_completion_item_choices(ac_app): @@ -742,10 +746,14 @@ def test_completion_item_choices(ac_app): assert len(ac_app.completion_matches) == len(ac_app.completion_item_choices) assert len(ac_app.display_matches) == len(ac_app.completion_item_choices) - # Make sure a completion table was created - first_result_line = normalize(ac_app.formatted_completions)[1] - assert 'choice_1' in first_result_line - assert 'A description' in first_result_line + # The table will show both the choice and description + description_displayed = False + for line in ac_app.formatted_completions.splitlines(): + if 'choice_1' in line and 'A description' in line: + description_displayed = True + break + + assert description_displayed @pytest.mark.parametrize( diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 928c323a..c541259e 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -31,9 +31,8 @@ from cmd2 import ( from .conftest import ( HELP_HISTORY, + SET_TXT, SHORTCUTS_TXT, - SHOW_LONG, - SHOW_TXT, complete_tester, normalize, odd_file_names, @@ -107,7 +106,7 @@ def test_base_argparse_help(base_app): def test_base_invalid_option(base_app): out, err = run_cmd(base_app, 'set -z') - assert err[0] == 'Usage: set [-h] [-v] [param] [value]' + assert err[0] == 'Usage: set [-h] [param] [value]' assert 'Error: unrecognized arguments: -z' in err[1] @@ -123,19 +122,11 @@ def test_command_starts_with_shortcut(): assert "Invalid command name 'help'" in str(excinfo.value) -def test_base_show(base_app): +def test_base_set(base_app): # force editor to be 'vim' so test is repeatable across platforms base_app.editor = 'vim' out, err = run_cmd(base_app, 'set') - expected = normalize(SHOW_TXT) - assert out == expected - - -def test_base_show_long(base_app): - # force editor to be 'vim' so test is repeatable across platforms - base_app.editor = 'vim' - out, err = run_cmd(base_app, 'set -v') - expected = normalize(SHOW_LONG) + expected = normalize(SET_TXT) assert out == expected @@ -150,7 +141,14 @@ now: True assert out == expected out, err = run_cmd(base_app, 'set quiet') - assert out == ['quiet: True'] + expected = normalize( + """ +Name Value Description +=================================================================================================== +quiet True Don't print nonessential feedback +""" + ) + assert out == expected def test_set_val_empty(base_app): @@ -1752,7 +1750,8 @@ def test_get_alias_completion_items(base_app): for cur_res in results: assert cur_res in base_app.aliases - assert cur_res.description == base_app.aliases[cur_res] + # Strip trailing spaces from table output + assert cur_res.description.rstrip() == base_app.aliases[cur_res] def test_get_macro_completion_items(base_app): @@ -1764,14 +1763,26 @@ def test_get_macro_completion_items(base_app): for cur_res in results: assert cur_res in base_app.macros - assert cur_res.description == base_app.macros[cur_res].value + # Strip trailing spaces from table output + assert cur_res.description.rstrip() == base_app.macros[cur_res].value def test_get_settable_completion_items(base_app): results = base_app._get_settable_completion_items() + assert len(results) == len(base_app.settables) + for cur_res in results: - assert cur_res in base_app.settables - assert cur_res.description == base_app.settables[cur_res].description + cur_settable = base_app.settables.get(cur_res) + assert cur_settable is not None + + # These CompletionItem descriptions are a two column table (Settable Value and Settable Description) + # First check if the description text starts with the value + str_value = str(cur_settable.get_value()) + assert cur_res.description.startswith(str_value) + + # The second column is likely to have wrapped long text. So we will just examine the + # first couple characters to look for the Settable's description. + assert cur_settable.description[0:10] in cur_res.description def test_alias_no_subcommand(base_app): diff --git a/tests/test_table_creator.py b/tests/test_table_creator.py index 70b77bad..e1bc8883 100644 --- a/tests/test_table_creator.py +++ b/tests/test_table_creator.py @@ -364,9 +364,12 @@ def test_simple_table_creation(): # No divider st = SimpleTable([column_1, column_2], divider_char=None) - table = st.generate_table(row_data) + no_divider_1 = st.generate_table(row_data) - assert table == ( + st = SimpleTable([column_1, column_2], divider_char='') + no_divider_2 = st.generate_table(row_data) + + assert no_divider_1 == no_divider_2 == ( 'Col 1 Col 2 \n' 'Col 1 Row 1 Col 2 Row 1 \n' '\n' diff --git a/tests/transcripts/regex_set.txt b/tests/transcripts/regex_set.txt index 623df8ed..68e61e30 100644 --- a/tests/transcripts/regex_set.txt +++ b/tests/transcripts/regex_set.txt @@ -3,14 +3,25 @@ # The regex for editor will match whatever program you use. # Regexes on prompts just make the trailing space obvious +(Cmd) set allow_style Terminal +allow_style - was: '/.*/' +now: 'Terminal' +(Cmd) set editor vim +editor - was: '/.*/' +now: 'vim' (Cmd) set -allow_style: /'(Terminal|Always|Never)'/ -always_show_hint: False -debug: False -echo: False -editor: /'.*'/ -feedback_to_output: False -max_completion_items: 50 -maxrepeats: 3 -quiet: False -timing: False +Name Value Description/ +/ +================================================================================================================== +allow_style Terminal Allow ANSI text style sequences in output (valid values:/ +/ + Terminal, Always, Never)/ +/ +always_show_hint False Display tab completion hint even when completion suggestions + print/ +/ +debug False Show full traceback on exception/ +/ +echo False Echo command issued into output/ +/ +editor vim Program used by 'edit'/ +/ +feedback_to_output False Include nonessentials in '|', '>' results/ +/ +max_completion_items 50 Maximum number of CompletionItems to display during tab/ +/ + completion/ +/ +maxrepeats 3 Max number of `--repeat`s allowed/ +/ +quiet False Don't print nonessential feedback/ +/ +timing False Report execution times/ +/ |
