summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py38
1 files changed, 13 insertions, 25 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 89aa9d03..6e4a5a3e 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -406,26 +406,21 @@ def test_history_output_file(base_app):
content = normalize(f.read())
assert content == expected
-def test_history_edit(base_app, mock):
+def test_history_edit(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
- count = [0]
-
- def fake_system(*args, **kwargs):
- count[0] += 1
-
- mock.patch.object(os, 'system', fake_system)
+ 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, 'history -e 1')
# We have an editor, so should expect a system call
- assert count[0] == 1
-
+ m.assert_called_once()
def test_history_run_all_commands(base_app):
# make sure we refuse to run all commands as a default
@@ -824,36 +819,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_blank(base_app, mock):
+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'
- count = [0]
-
- def fake_system(*args, **kwargs):
- count[0] += 1
-
- mock.patch.object(os, 'system', fake_system)
+ # 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_cmd(base_app, 'edit')
# We have an editor, so should expect a system call
- assert count[0] == 1
+ m.assert_called_once()
-def test_base_py_interactive(base_app, mock):
+def test_base_py_interactive(base_app):
# Mock out the InteractiveConsole.interact() call so we don't actually wait for a user's response on stdin
- count = [0]
-
- def fake_interact(*args, **kwargs):
- count[0] += 1
-
- mock.patch.object(InteractiveConsole, 'interact', fake_interact)
+ m = mock.MagicMock(name='interact')
+ InteractiveConsole.interact = m
run_cmd(base_app, "py")
# Make sure our mock was called once and only once
- assert count[0] == 1
+ m.assert_called_once()
def test_exclude_from_history(base_app, monkeypatch):