summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py10
-rwxr-xr-xtests/test_cmd2.py33
-rw-r--r--tests/test_transcript.py4
-rw-r--r--tests/transcripts/regex_set.txt4
4 files changed, 16 insertions, 35 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index b8abc4a5..51345881 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -88,10 +88,10 @@ SHORTCUTS_TXT = """Shortcuts for other commands:
"""
# Output from the show command with default settings
-SHOW_TXT = """allow_style: Terminal
+SHOW_TXT = """allow_style: 'Terminal'
debug: False
echo: False
-editor: vim
+editor: 'vim'
feedback_to_output: False
max_completion_items: 50
quiet: False
@@ -99,11 +99,11 @@ timing: False
"""
SHOW_LONG = """
-allow_style: Terminal # Allow ANSI text style sequences in output (valid values: Terminal, Always, Never)
+allow_style: 'Terminal' # Allow ANSI text style sequences in output (valid values: Terminal, Always, Never)
debug: False # Show full error stack on error
echo: False # Echo command issued into output
-editor: vim # Program used by ``edit``
-feedback_to_output: False # Include nonessentials in `|`, `>` results
+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
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')
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index 5739ad8e..64c95b30 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -16,7 +16,7 @@ import pytest
import cmd2
from .conftest import run_cmd, verify_help_text
from cmd2 import transcript
-from cmd2.utils import StdSim
+from cmd2.utils import StdSim, Settable
class CmdLineApp(cmd2.Cmd):
@@ -31,7 +31,7 @@ class CmdLineApp(cmd2.Cmd):
super().__init__(*args, multiline_commands=['orate'], **kwargs)
# Make maxrepeats settable at runtime
- self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed'
+ self.add_settable(Settable('maxrepeats', int, 'Max number of `--repeat`s allowed'))
self.intro = 'This is an intro banner ...'
diff --git a/tests/transcripts/regex_set.txt b/tests/transcripts/regex_set.txt
index 5bf9add3..5004adc5 100644
--- a/tests/transcripts/regex_set.txt
+++ b/tests/transcripts/regex_set.txt
@@ -4,10 +4,10 @@
# Regexes on prompts just make the trailing space obvious
(Cmd) set
-allow_style: /(Terminal|Always|Never)/
+allow_style: /'(Terminal|Always|Never)'/
debug: False
echo: False
-editor: /.*/
+editor: /'.*'/
feedback_to_output: False
max_completion_items: 50
maxrepeats: 3