summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py5
-rw-r--r--tests/test_cmd2.py25
2 files changed, 19 insertions, 11 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 31399620..07e7fcec 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -563,8 +563,9 @@ class Cmd(cmd.Cmd):
@allow_ansi.setter
def allow_ansi(self, new_val: str) -> None:
- """Read-only property needed to support do_set when it sets allow_ansi"""
- if new_val.lower() not in (ansi.ANSI_TERMINAL.lower(), ansi.ANSI_ALWAYS.lower(), ansi.ANSI_NEVER.lower()):
+ """Setter property needed to support do_set when it updates allow_ansi"""
+ new_val = new_val.capitalize()
+ if new_val not in (ansi.ANSI_TERMINAL, ansi.ANSI_ALWAYS, ansi.ANSI_NEVER):
self.perror('Invalid value: {} (valid values: {}, {}, {})'.format(new_val, ansi.ANSI_TERMINAL,
ansi.ANSI_ALWAYS, ansi.ANSI_NEVER))
else:
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index ab24384b..d3e51130 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -181,18 +181,25 @@ now: True
out, err = run_cmd(base_app, 'set quiet')
assert out == ['quiet: True']
-@pytest.mark.parametrize('new_val, is_valid', [
- (ansi.ANSI_NEVER, False),
- (ansi.ANSI_TERMINAL, False),
- (ansi.ANSI_ALWAYS, False),
- ('neVeR', False),
- ('TeRMInal', False),
- ('AlWaYs', False),
- ('invalid', True),
+@pytest.mark.parametrize('new_val, is_valid, expected', [
+ (ansi.ANSI_NEVER, False, ansi.ANSI_NEVER),
+ ('neVeR', False, ansi.ANSI_NEVER),
+ (ansi.ANSI_TERMINAL, False, ansi.ANSI_TERMINAL),
+ ('TeRMInal', False, ansi.ANSI_TERMINAL),
+ (ansi.ANSI_ALWAYS, False, ansi.ANSI_ALWAYS),
+ ('AlWaYs', False, ansi.ANSI_ALWAYS),
+ ('invalid', True, ansi.ANSI_TERMINAL),
])
-def test_set_allow_ansi(base_app, new_val, is_valid):
+def test_set_allow_ansi(base_app, new_val, is_valid, expected):
+ # Initialize allow_ansi for this test
+ ansi.allow_ansi = ansi.ANSI_TERMINAL
+
+ # Use the set command to alter it
out, err = run_cmd(base_app, 'set allow_ansi {}'.format(new_val))
+
+ # Verify the results
assert bool(err) == is_valid
+ assert ansi.allow_ansi == expected
# Reload ansi module to reset allow_ansi to its default since it's an
# application-wide setting that can affect other unit tests.