diff options
author | kmvanbrunt <kmvanbrunt@gmail.com> | 2018-07-12 01:35:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-12 01:35:46 -0400 |
commit | 5d2133ae8e67435d1f2af17cd80d0490c0ba0f82 (patch) | |
tree | a82f2b99f497ee6cfab0edf789a1b5195e6bc99f /tests | |
parent | ea7a4bbd14a41b0e9bdde8d34c666eb35df60c4a (diff) | |
parent | 4a233b8148add8b89847fbeab141ca15737e44f2 (diff) | |
download | cmd2-git-5d2133ae8e67435d1f2af17cd80d0490c0ba0f82.tar.gz |
Merge pull request #467 from python-cmd2/history
History clear
Diffstat (limited to 'tests')
-rw-r--r-- | tests/conftest.py | 7 | ||||
-rw-r--r-- | tests/test_cmd2.py | 43 |
2 files changed, 37 insertions, 13 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 90d45bd9..3f3b862e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -37,7 +37,7 @@ Documented commands (type help <topic>): alias Define or display aliases edit Edit a file in a text editor. help List available commands with "help" or detailed help with "help cmd". -history View, run, edit, and save previously entered commands. +history View, run, edit, save, or clear previously entered commands. load Runs commands in script file that is encoded as either ASCII or UTF-8 text. py Invoke python command, shell, or script pyscript Runs a python script file inside the console @@ -49,9 +49,9 @@ unalias Unsets aliases """ # Help text for the history command -HELP_HISTORY = """usage: history [-h] [-r | -e | -s | -o FILE | -t TRANSCRIPT] [arg] +HELP_HISTORY = """usage: history [-h] [-r | -e | -s | -o FILE | -t TRANSCRIPT | -c] [arg] -View, run, edit, and save previously entered commands. +View, run, edit, save, or clear previously entered commands. positional arguments: arg empty all history items @@ -69,6 +69,7 @@ optional arguments: output commands to a script file -t TRANSCRIPT, --transcript TRANSCRIPT output commands and results to a transcript file + -c, --clear clears all history """ # Output from the shortcuts command with default built-in shortcuts diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index b973fdf5..e5dd3baa 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -231,7 +231,7 @@ def test_pyscript_with_nonexist_file(base_app, capsys): python_script = 'does_not_exist.py' run_cmd(base_app, "pyscript {}".format(python_script)) out, err = capsys.readouterr() - assert err.startswith("EXCEPTION of type 'FileNotFoundError' occurred with message:") + assert "Error opening script file" in err def test_pyscript_with_exception(base_app, capsys, request): test_dir = os.path.dirname(request.module.__file__) @@ -426,7 +426,7 @@ def test_history_run_all_commands(base_app): out = 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 occured because if the commaned executed + # standard out, that the error occurred because if the command executed # then we should have a list of shortcuts in our output assert out == [] @@ -435,6 +435,23 @@ def test_history_run_one_command(base_app): output = run_cmd(base_app, 'history -r 1') assert output == expected +def test_history_clear(base_app): + # Add commands to history + run_cmd(base_app, 'help') + run_cmd(base_app, 'alias') + + # Make sure history has items + out = 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') + assert out == [] + + def test_base_load(base_app, request): test_dir = os.path.dirname(request.module.__file__) filename = os.path.join(test_dir, 'script.txt') @@ -457,8 +474,7 @@ def test_load_with_empty_args(base_app, capsys): out, err = capsys.readouterr() # The load command requires a file path argument, so we should get an error message - expected = normalize("""ERROR: load command requires a file path:\n""") - assert normalize(str(err)) == expected + assert "load command requires a file path" in str(err) assert base_app.cmdqueue == [] @@ -468,10 +484,18 @@ def test_load_with_nonexistent_file(base_app, capsys): out, err = capsys.readouterr() # The load command requires a path to an existing file - assert str(err).startswith("ERROR") - assert "does not exist or is not a file" in str(err) + assert "does not exist" in str(err) assert base_app.cmdqueue == [] +def test_load_with_directory(base_app, capsys, request): + test_dir = os.path.dirname(request.module.__file__) + + # The way the load command works, we can't directly capture its stdout or stderr + run_cmd(base_app, 'load {}'.format(test_dir)) + out, err = capsys.readouterr() + + assert "is not a file" in str(err) + assert base_app.cmdqueue == [] def test_load_with_empty_file(base_app, capsys, request): test_dir = os.path.dirname(request.module.__file__) @@ -481,8 +505,7 @@ def test_load_with_empty_file(base_app, capsys, request): run_cmd(base_app, 'load {}'.format(filename)) out, err = capsys.readouterr() - # The load command requires non-empty scripts files - assert str(err).startswith("ERROR") + # The load command requires non-empty script files assert "is empty" in str(err) assert base_app.cmdqueue == [] @@ -724,7 +747,7 @@ def test_pipe_to_shell(base_app, capsys): out, err = capsys.readouterr() # Unfortunately with the improved way of piping output to a subprocess, there isn't any good way of getting - # access to the output produced by that subprocess within a unit test, but we can verify that no error occured + # access to the output produced by that subprocess within a unit test, but we can verify that no error occurred assert not err def test_pipe_to_shell_error(base_app, capsys): @@ -1225,7 +1248,7 @@ Other ================================================================================ alias Define or display aliases help List available commands with "help" or detailed help with "help cmd". -history View, run, edit, and save previously entered commands. +history View, run, edit, save, or clear previously entered commands. load Runs commands in script file that is encoded as either ASCII or UTF-8 text. py Invoke python command, shell, or script pyscript Runs a python script file inside the console |