summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-09-23 17:42:12 -0400
committerGitHub <noreply@github.com>2017-09-23 17:42:12 -0400
commitb16b91268ecbea934e96a68b7feb2965f4ab3c18 (patch)
treeb135107eef9dd2ed617cc7baf78a2070c5519dd6 /tests
parent7388e0d256f4e37a0003e3e8ff5ebf47b09aeaf3 (diff)
parent1c60c8a7ebc3654e9ddf80d5306cbfb7bac7aaed (diff)
downloadcmd2-git-b16b91268ecbea934e96a68b7feb2965f4ab3c18.tar.gz
Merge pull request #228 from python-cmd2/edit_index_bug
Fixed a bug when edit is passed an integer outside the range of history indices
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py64
1 files changed, 56 insertions, 8 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 0ea3db4d..c395acc3 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -812,7 +812,29 @@ def test_edit_file_with_spaces(base_app, request, monkeypatch):
# We think we have an editor, so should expect a system call
m.assert_called_once_with('"{}" "{}"'.format(base_app.editor, filename))
-def test_edit_number(base_app, monkeypatch):
+def test_edit_blank(base_app, monkeypatch):
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
+ base_app.editor = 'fooedit'
+
+ # Mock out the os.system call so we don't actually open an editor
+ m = mock.MagicMock(name='system')
+ monkeypatch.setattr("os.system", m)
+
+ # Run help command just so we have a command in history
+ run_cmd(base_app, 'help')
+
+ run_cmd(base_app, 'edit')
+
+ # We have an editor, so should expect a system call
+ m.assert_called_once()
+
+def test_edit_empty_history(base_app, capsys):
+ run_cmd(base_app, 'edit')
+ out, err = capsys.readouterr()
+ assert out == ''
+ assert err == 'ERROR: edit must be called with argument if history is empty\n'
+
+def test_edit_valid_positive_number(base_app, monkeypatch):
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
base_app.editor = 'fooedit'
@@ -828,7 +850,7 @@ def test_edit_number(base_app, monkeypatch):
# We have an editor, so should expect a system call
m.assert_called_once()
-def test_edit_blank(base_app, monkeypatch):
+def test_edit_valid_negative_number(base_app, monkeypatch):
# Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
base_app.editor = 'fooedit'
@@ -839,16 +861,42 @@ def test_edit_blank(base_app, monkeypatch):
# Run help command just so we have a command in history
run_cmd(base_app, 'help')
- run_cmd(base_app, 'edit')
+ run_cmd(base_app, 'edit "-1"')
# We have an editor, so should expect a system call
m.assert_called_once()
-def test_edit_empty_history(base_app, capsys):
- run_cmd(base_app, 'edit')
- out, err = capsys.readouterr()
- assert out == ''
- assert err == 'ERROR: edit must be called with argument if history is empty\n'
+def test_edit_invalid_positive_number(base_app, monkeypatch):
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
+ base_app.editor = 'fooedit'
+
+ # Mock out the os.system call so we don't actually open an editor
+ m = mock.MagicMock(name='system')
+ monkeypatch.setattr("os.system", m)
+
+ # Run help command just so we have a command in history
+ run_cmd(base_app, 'help')
+
+ run_cmd(base_app, 'edit 23')
+
+ # History index is invalid, so should expect a system call
+ m.assert_not_called()
+
+def test_edit_invalid_negative_number(base_app, monkeypatch):
+ # Set a fake editor just to make sure we have one. We aren't really going to call it due to the mock
+ base_app.editor = 'fooedit'
+
+ # Mock out the os.system call so we don't actually open an editor
+ m = mock.MagicMock(name='system')
+ monkeypatch.setattr("os.system", m)
+
+ # Run help command just so we have a command in history
+ run_cmd(base_app, 'help')
+
+ run_cmd(base_app, 'edit "-23"')
+
+ # History index is invalid, so should expect a system call
+ m.assert_not_called()
def test_base_py_interactive(base_app):