summaryrefslogtreecommitdiff
path: root/tests/test_cmd2.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-16 20:59:33 -0700
committerkotfu <kotfu@kotfu.net>2018-01-16 20:59:33 -0700
commitd8ade122f0cd23dfcad18872536cc3709334e77f (patch)
treecedb32b8d1216b048cbab8f632b2bee343cf2967 /tests/test_cmd2.py
parent60890fa5f0d6650814384fc8db19875eaff08143 (diff)
downloadcmd2-git-d8ade122f0cd23dfcad18872536cc3709334e77f.tar.gz
Remove do_save() and do_run() for #252
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r--tests/test_cmd2.py108
1 files changed, 4 insertions, 104 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 559a2258..8ee41096 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -356,12 +356,9 @@ def test_history_run_all_commands(base_app):
assert out == []
def test_history_run_one_command(base_app):
- run_cmd(base_app, 'help')
- # because of the way run_cmd works, it will not
- # process the cmdqueue. So we can check to see
- # if the cmdqueue has a waiting item
- run_cmd(base_app, 'history -r 1')
- assert len(base_app.cmdqueue) == 1
+ expected = run_cmd(base_app, 'help')
+ output = run_cmd(base_app, 'history -r 1')
+ assert output == expected
def test_base_load(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
@@ -525,88 +522,6 @@ def test_relative_load_requires_an_argument(base_app, capsys):
assert base_app.cmdqueue == []
-def test_base_save(base_app):
- # TODO: Use a temporary directory for the file
- filename = 'deleteme.txt'
- base_app.feedback_to_output = True
- run_cmd(base_app, 'help')
- run_cmd(base_app, 'help save')
-
- # Test the * form of save which saves all commands from history
- out = run_cmd(base_app, 'save * {}'.format(filename))
- assert out == normalize('Saved to {}\n'.format(filename))
- expected = normalize("""
-help
-
-help save
-
-save * deleteme.txt
-""")
- with open(filename) as f:
- content = normalize(f.read())
- assert content == expected
-
- # Test the N form of save which saves a numbered command from history
- out = run_cmd(base_app, 'save 1 {}'.format(filename))
- assert out == normalize('Saved to {}\n'.format(filename))
- expected = normalize('help')
- with open(filename) as f:
- content = normalize(f.read())
- assert content == expected
-
- # Test the blank form of save which saves the most recent command from history
- out = run_cmd(base_app, 'save {}'.format(filename))
- assert out == normalize('Saved to {}\n'.format(filename))
- expected = normalize('save 1 {}'.format(filename))
- with open(filename) as f:
- content = normalize(f.read())
- assert content == expected
-
- # Delete file that was created
- os.remove(filename)
-
-def test_save_parse_error(base_app, capsys):
- invalid_file = '~!@'
- run_cmd(base_app, 'save {}'.format(invalid_file))
- out, err = capsys.readouterr()
- assert out == ''
- assert err.startswith('ERROR: Could not understand save target {}\n'.format(invalid_file))
-
-def test_save_tempfile(base_app):
- # Just run help to make sure there is something in the history
- base_app.feedback_to_output = True
- run_cmd(base_app, 'help')
- out = run_cmd(base_app, 'save *')
- output = out[0]
- assert output.startswith('Saved to ')
-
- # Delete the tempfile which was created
- temp_file = output.split('Saved to ')[1].strip()
- os.remove(temp_file)
-
-def test_save_invalid_history_index(base_app, capsys):
- run_cmd(base_app, 'save 5')
- out, err = capsys.readouterr()
- assert out == ''
- assert err.startswith("EXCEPTION of type 'IndexError' occurred with message: 'list index out of range'\n")
-
-def test_save_empty_history_and_index(base_app, capsys):
- run_cmd(base_app, 'save')
- out, err = capsys.readouterr()
- assert out == ''
- assert err.startswith("ERROR: History is empty, nothing to save.\n")
-
-def test_save_invalid_path(base_app, capsys):
- # Just run help to make sure there is something in the history
- run_cmd(base_app, 'help')
-
- invalid_path = '/no_such_path/foobar.txt'
- run_cmd(base_app, 'save {}'.format(invalid_path))
- out, err = capsys.readouterr()
- assert out == ''
- assert err.startswith("ERROR: Saving '{}' - ".format(invalid_path))
-
-
def test_output_redirection(base_app):
fd, filename = tempfile.mkstemp(prefix='cmd2_test', suffix='.txt')
os.close(fd)
@@ -1144,8 +1059,7 @@ def test_custom_help_menu(help_app):
expected = normalize("""
Documented commands (type help <topic>):
========================================
-edit history py quit save shell squat
-help load pyscript run set shortcuts
+edit help history load py pyscript quit set shell shortcuts squat
Undocumented commands:
======================
@@ -1406,20 +1320,6 @@ def test_clipboard_failure(capsys):
assert 'Cannot redirect to paste buffer; install ``xclip`` and re-run to enable' in err
-def test_run_command_with_empty_arg(base_app):
- command = 'help'
- base_app.feedback_to_output = True
- run_cmd(base_app, command)
- out = run_cmd(base_app, 'run')
- expected = normalize('{}\n\n'.format(command) + BASE_HELP)
- assert out == expected
-
-def test_run_command_with_empty_history(base_app):
- base_app.feedback_to_output = True
- out = run_cmd(base_app, 'run')
- assert out == []
-
-
class CmdResultApp(cmd2.Cmd):
def __init__(self, *args, **kwargs):
# Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x