summaryrefslogtreecommitdiff
path: root/tests/test_history.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-20 20:23:14 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-20 20:23:14 -0400
commit9ffb1ffa80724b10e5be5563fdefcf67a5abff41 (patch)
tree4df73432c1c50fc01e87847362cc12986e424686 /tests/test_history.py
parentd16a20fe14ed02e389ccde99d114e7335740e162 (diff)
downloadcmd2-git-9ffb1ffa80724b10e5be5563fdefcf67a5abff41.tar.gz
Made run_cmd return out and err
Diffstat (limited to 'tests/test_history.py')
-rw-r--r--tests/test_history.py80
1 files changed, 39 insertions, 41 deletions
diff --git a/tests/test_history.py b/tests/test_history.py
index 9046e877..058386a3 100644
--- a/tests/test_history.py
+++ b/tests/test_history.py
@@ -16,13 +16,11 @@ except ImportError:
from unittest import mock
import cmd2
-from cmd2 import clipboard
-from cmd2 import utils
from .conftest import run_cmd, normalize, HELP_HISTORY
def test_base_help_history(base_app):
- out = run_cmd(base_app, 'help history')
+ out, err = run_cmd(base_app, 'help history')
assert out == normalize(HELP_HISTORY)
def test_exclude_from_history(base_app, monkeypatch):
@@ -40,14 +38,14 @@ def test_exclude_from_history(base_app, monkeypatch):
run_cmd(base_app, 'history')
# Verify that the history is empty
- out = run_cmd(base_app, 'history')
+ out, err = run_cmd(base_app, 'history')
assert out == []
# Now run a command which isn't excluded from the history
run_cmd(base_app, 'help')
# And verify we have a history now ...
- out = run_cmd(base_app, 'history')
+ out, err = run_cmd(base_app, 'history')
expected = normalize(""" 1 help""")
assert out == expected
@@ -126,20 +124,20 @@ def test_history_regex_search(hist):
def test_base_history(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
- out = run_cmd(base_app, 'history')
+ out, err = run_cmd(base_app, 'history')
expected = normalize("""
1 help
2 shortcuts
""")
assert out == expected
- out = run_cmd(base_app, 'history he')
+ out, err = run_cmd(base_app, 'history he')
expected = normalize("""
1 help
""")
assert out == expected
- out = run_cmd(base_app, 'history sh')
+ out, err = run_cmd(base_app, 'history sh')
expected = normalize("""
2 shortcuts
""")
@@ -148,7 +146,7 @@ def test_base_history(base_app):
def test_history_script_format(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
- out = run_cmd(base_app, 'history -s')
+ out, err = run_cmd(base_app, 'history -s')
expected = normalize("""
help
shortcuts
@@ -159,7 +157,7 @@ def test_history_with_string_argument(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
run_cmd(base_app, 'help history')
- out = run_cmd(base_app, 'history help')
+ out, err = run_cmd(base_app, 'history help')
expected = normalize("""
1 help
3 help history
@@ -171,7 +169,7 @@ def test_history_expanded_with_string_argument(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'help history')
run_cmd(base_app, 'sc')
- out = run_cmd(base_app, 'history -v shortcuts')
+ out, err = run_cmd(base_app, 'history -v shortcuts')
expected = normalize("""
1 alias create sc shortcuts
4 sc
@@ -184,7 +182,7 @@ def test_history_expanded_with_regex_argument(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'help history')
run_cmd(base_app, 'sc')
- out = run_cmd(base_app, 'history -v /sh.*cuts/')
+ out, err = run_cmd(base_app, 'history -v /sh.*cuts/')
expected = normalize("""
1 alias create sc shortcuts
4 sc
@@ -195,7 +193,7 @@ def test_history_expanded_with_regex_argument(base_app):
def test_history_with_integer_argument(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
- out = run_cmd(base_app, 'history 1')
+ out, err = run_cmd(base_app, 'history 1')
expected = normalize("""
1 help
""")
@@ -206,7 +204,7 @@ def test_history_with_integer_span(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
run_cmd(base_app, 'help history')
- out = run_cmd(base_app, 'history 1..2')
+ out, err = run_cmd(base_app, 'history 1..2')
expected = normalize("""
1 help
2 shortcuts
@@ -217,7 +215,7 @@ def test_history_with_span_start(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
run_cmd(base_app, 'help history')
- out = run_cmd(base_app, 'history 2:')
+ out, err = run_cmd(base_app, 'history 2:')
expected = normalize("""
2 shortcuts
3 help history
@@ -228,7 +226,7 @@ def test_history_with_span_end(base_app):
run_cmd(base_app, 'help')
run_cmd(base_app, 'shortcuts')
run_cmd(base_app, 'help history')
- out = run_cmd(base_app, 'history :2')
+ out, err = run_cmd(base_app, 'history :2')
expected = normalize("""
1 help
2 shortcuts
@@ -240,8 +238,8 @@ def test_history_with_span_index_error(base_app):
run_cmd(base_app, 'help history')
run_cmd(base_app, '!ls -hal :')
with pytest.raises(ValueError):
- _, err = run_cmd(base_app, 'history "hal :"')
- assert "ValueError" in err
+ out, err = run_cmd(base_app, 'history "hal :"')
+ assert "ValueError" in err[0]
def test_history_output_file(base_app):
run_cmd(base_app, 'help')
@@ -275,7 +273,7 @@ def test_history_edit(base_app, monkeypatch):
def test_history_run_all_commands(base_app):
# make sure we refuse to run all commands as a default
run_cmd(base_app, 'shortcuts')
- out = run_cmd(base_app, 'history -r')
+ out, err = run_cmd(base_app, 'history -r')
# this should generate an error, but we don't currently have a way to
# capture stderr in these tests. So we assume that if we got nothing on
# standard out, that the error occurred because if the command executed
@@ -283,9 +281,9 @@ def test_history_run_all_commands(base_app):
assert out == []
def test_history_run_one_command(base_app):
- expected = run_cmd(base_app, 'help')
- output = run_cmd(base_app, 'history -r 1')
- assert output == expected
+ out1, err1 = run_cmd(base_app, 'help')
+ out2, err2 = run_cmd(base_app, 'history -r 1')
+ assert out1 == out2
def test_history_clear(base_app):
# Add commands to history
@@ -293,72 +291,72 @@ def test_history_clear(base_app):
run_cmd(base_app, 'alias')
# Make sure history has items
- out = run_cmd(base_app, 'history')
+ out, err = run_cmd(base_app, 'history')
assert out
# Clear the history
run_cmd(base_app, 'history --clear')
# Make sure history is empty
- out = run_cmd(base_app, 'history')
+ out, err = run_cmd(base_app, 'history')
assert out == []
def test_history_verbose_with_other_options(base_app):
# make sure -v shows a usage error if any other options are present
options_to_test = ['-r', '-e', '-o file', '-t file', '-c', '-x']
for opt in options_to_test:
- output = run_cmd(base_app, 'history -v ' + opt)
- assert len(output) == 3
- assert output[1].startswith('Usage:')
+ out, err = run_cmd(base_app, 'history -v ' + opt)
+ assert len(out) == 3
+ assert out[1].startswith('Usage:')
def test_history_verbose(base_app):
# validate function of -v option
run_cmd(base_app, 'alias create s shortcuts')
run_cmd(base_app, 's')
- output = run_cmd(base_app, 'history -v')
- assert len(output) == 3
+ out, err = run_cmd(base_app, 'history -v')
+ assert len(out) == 3
# TODO test for basic formatting once we figure it out
def test_history_script_with_invalid_options(base_app):
# make sure -s shows a usage error if -c, -r, -e, -o, or -t are present
options_to_test = ['-r', '-e', '-o file', '-t file', '-c']
for opt in options_to_test:
- output = run_cmd(base_app, 'history -s ' + opt)
- assert len(output) == 3
- assert output[1].startswith('Usage:')
+ out, err = run_cmd(base_app, 'history -s ' + opt)
+ assert len(out) == 3
+ assert out[1].startswith('Usage:')
def test_history_script(base_app):
cmds = ['alias create s shortcuts', 's']
for cmd in cmds:
run_cmd(base_app, cmd)
- output = run_cmd(base_app, 'history -s')
- assert output == cmds
+ out, err = run_cmd(base_app, 'history -s')
+ assert out == cmds
def test_history_expanded_with_invalid_options(base_app):
# make sure -x shows a usage error if -c, -r, -e, -o, or -t are present
options_to_test = ['-r', '-e', '-o file', '-t file', '-c']
for opt in options_to_test:
- output = run_cmd(base_app, 'history -x ' + opt)
- assert len(output) == 3
- assert output[1].startswith('Usage:')
+ out, err = run_cmd(base_app, 'history -x ' + opt)
+ assert len(out) == 3
+ assert out[1].startswith('Usage:')
def test_history_expanded(base_app):
# validate function of -x option
cmds = ['alias create s shortcuts', 's']
for cmd in cmds:
run_cmd(base_app, cmd)
- output = run_cmd(base_app, 'history -x')
+ out, err = run_cmd(base_app, 'history -x')
expected = [' 1 alias create s shortcuts', ' 2 shortcuts']
- assert output == expected
+ assert out == expected
def test_history_script_expanded(base_app):
# validate function of -s -x options together
cmds = ['alias create s shortcuts', 's']
for cmd in cmds:
run_cmd(base_app, cmd)
- output = run_cmd(base_app, 'history -sx')
+ out, err = run_cmd(base_app, 'history -sx')
expected = ['alias create s shortcuts', 'shortcuts']
- assert output == expected
+ assert out == expected
#####