diff options
author | kotfu <kotfu@kotfu.net> | 2018-01-16 20:59:33 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-01-16 20:59:33 -0700 |
commit | d8ade122f0cd23dfcad18872536cc3709334e77f (patch) | |
tree | cedb32b8d1216b048cbab8f632b2bee343cf2967 /tests | |
parent | 60890fa5f0d6650814384fc8db19875eaff08143 (diff) | |
download | cmd2-git-d8ade122f0cd23dfcad18872536cc3709334e77f.tar.gz |
Remove do_save() and do_run() for #252
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 2 | ||||
-rw-r--r-- | tests/test_cmd2.py | 108 | ||||
-rw-r--r-- | tests/test_transcript.py | 6 | ||||
-rw-r--r-- | tests/transcripts/from_cmdloop.txt | 8 |
4 files changed, 12 insertions, 112 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 5ecb6f82..89a3bbf8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,7 +15,7 @@ import cmd2 # Help text for base cmd2.Cmd application BASE_HELP = """Documented commands (type help <topic>): ======================================== -edit help history load py pyscript quit run save set shell shortcuts +edit help history load py pyscript quit set shell shortcuts """ # Help text for the history command 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 diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 193e135f..41322341 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -130,8 +130,8 @@ def test_base_with_transcript(_cmdline_app): Documented commands (type help <topic>): ======================================== -edit history mumble py quit save set shortcuts -help load orate pyscript run say shell speak +edit history mumble py quit set shortcuts +help load orate pyscript say shell speak (Cmd) help say Repeats what you tell me to. @@ -172,7 +172,7 @@ say -ps --repeat=5 goodnight, Gracie set maxrepeats 5 -------------------------[6] say -ps --repeat=5 goodnight, Gracie -(Cmd) run 4 +(Cmd) history -r 4 OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY diff --git a/tests/transcripts/from_cmdloop.txt b/tests/transcripts/from_cmdloop.txt index 3deed8cf..07bdc30d 100644 --- a/tests/transcripts/from_cmdloop.txt +++ b/tests/transcripts/from_cmdloop.txt @@ -5,8 +5,8 @@ Documented commands (type help <topic>): ======================================== -edit history mumble py quit save set shortcuts/ */ -help load orate pyscript run say shell speak/ */ +edit history mumble py quit set shortcuts/ */ +help load orate pyscript say shell speak/ */ (Cmd) help say Repeats what you tell me to. @@ -34,7 +34,7 @@ OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY -(Cmd) hi +(Cmd) history -------------------------[1] help -------------------------[2] @@ -47,7 +47,7 @@ say -ps --repeat=5 goodnight, Gracie set maxrepeats 5 -------------------------[6] say -ps --repeat=5 goodnight, Gracie -(Cmd) run 4 +(Cmd) history -r 4 say -ps --repeat=5 goodnight, Gracie OODNIGHT, GRACIEGAY OODNIGHT, GRACIEGAY |