summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-04 17:44:35 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-02-04 17:44:35 -0500
commita5d3f7959c252ee23cf6360b81292d376b8c6fcc (patch)
treec5e03847b6d37bd2bb6155957d10332268224783 /tests/test_cmd2.py
parent60a212c1c585f0c4c06ffcfeb9882520af8dbf35 (diff)
downloadcmd2-git-a5d3f7959c252ee23cf6360b81292d376b8c6fcc.tar.gz
Updated set command to support tab completion of values
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-xtests/test_cmd2.py33
1 files changed, 7 insertions, 26 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index a3dbe1be..8b14949c 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -79,7 +79,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] [-a] [-l] [param] [value]'
+ assert err[0] == 'Usage: set [-h] [-l] [param] [value]'
assert 'Error: unrecognized arguments: -z' in err[1]
def test_base_shortcuts(base_app):
@@ -108,16 +108,6 @@ def test_base_show_long(base_app):
assert out == expected
-def test_base_show_readonly(base_app):
- base_app.editor = 'vim'
- out, err = run_cmd(base_app, 'set -a')
- expected = normalize(SHOW_TXT + '\nRead only settings:' + """
- Commands may be terminated with: {}
- Output redirection and pipes allowed: {}
-""".format(base_app.statement_parser.terminators, base_app.allow_redirection))
- assert out == expected
-
-
def test_cast():
# Boolean
assert utils.cast(True, True) == True
@@ -175,16 +165,6 @@ Parameter 'qqq' not supported (type 'set' for list of parameters).
""")
assert err == expected
-def test_set_quiet(base_app):
- out, err = run_cmd(base_app, 'set quie True')
- expected = normalize("""
-quiet - was: False
-now: True
-""")
- assert out == expected
-
- out, err = run_cmd(base_app, 'set quiet')
- assert out == ['quiet: True']
@pytest.mark.parametrize('new_val, is_valid, expected', [
(ansi.STYLE_NEVER, False, ansi.STYLE_NEVER),
@@ -214,10 +194,11 @@ def test_set_allow_style(base_app, new_val, is_valid, expected):
class OnChangeHookApp(cmd2.Cmd):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+ self.add_settable(utils.Settable('quiet', bool, "my description", onchange_cb=self._onchange_quiet))
- def _onchange_quiet(self, old, new) -> None:
+ def _onchange_quiet(self, name, old, new) -> None:
"""Runs when quiet is changed via set command"""
- self.poutput("You changed quiet")
+ self.poutput("You changed " + name)
@pytest.fixture
def onchange_app():
@@ -671,7 +652,7 @@ now: True
def test_debug_not_settable(base_app):
# Set debug to False and make it unsettable
base_app.debug = False
- del base_app.settable['debug']
+ del base_app.settables['debug']
# Cause an exception
out, err = run_cmd(base_app, 'bad "quote')
@@ -1583,8 +1564,8 @@ def test_get_macro_completion_items(base_app):
def test_get_settable_completion_items(base_app):
results = base_app._get_settable_completion_items()
for cur_res in results:
- assert cur_res in base_app.settable
- assert cur_res.description == base_app.settable[cur_res]
+ assert cur_res in base_app.settables
+ assert cur_res.description == base_app.settables[cur_res].description
def test_alias_no_subcommand(base_app):
out, err = run_cmd(base_app, 'alias')