diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-07-12 00:58:57 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2018-07-12 00:58:57 -0400 |
commit | d52fe23f70cddfb53005d0e9f05f1a7dceea8fbb (patch) | |
tree | 7ffd6897016d3cfa19abc34722086f98985ceaad /tests | |
parent | 297eff0540c2115d817dbe4338830b23bdddd9a0 (diff) | |
download | cmd2-git-d52fe23f70cddfb53005d0e9f05f1a7dceea8fbb.tar.gz |
Added unit tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 95970436..e5dd3baa 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -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') @@ -470,6 +487,15 @@ def test_load_with_nonexistent_file(base_app, capsys): 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__) @@ -479,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 == [] @@ -722,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): |