diff options
author | kmvanbrunt <kmvanbrunt@gmail.com> | 2019-02-21 21:00:01 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-21 21:00:01 -0500 |
commit | bb376455b46e2fceba21120eba976465ea8d2c5a (patch) | |
tree | d4dda51dc5ddbd1c691a79b7adb3ad489d6f6db5 /tests/test_cmd2.py | |
parent | 086d4db5e10b9bfe64c767a2dad9c38fe95f299c (diff) | |
parent | befeaafa59acd86fd5b467dc459e8df131bf03eb (diff) | |
download | cmd2-git-bb376455b46e2fceba21120eba976465ea8d2c5a.tar.gz |
Merge pull request #628 from python-cmd2/simplify_edit
Removed os.system in favor of do_shell
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 09c4fa6c..8b6035bd 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -459,15 +459,15 @@ def test_history_edit(base_app, monkeypatch): # 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) + # Mock out the subprocess.Popen call so we don't actually open an editor + m = mock.MagicMock(name='Popen') + monkeypatch.setattr("subprocess.Popen", 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 + # We have an editor, so should expect a Popen call m.assert_called_once() def test_history_run_all_commands(base_app): @@ -883,46 +883,44 @@ def test_edit_file(base_app, request, monkeypatch): 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) + m = mock.MagicMock(name='Popen') + monkeypatch.setattr("subprocess.Popen", m) test_dir = os.path.dirname(request.module.__file__) filename = os.path.join(test_dir, 'script.txt') run_cmd(base_app, 'edit {}'.format(filename)) - # We think we have an editor, so should expect a system call - m.assert_called_once_with('{} {}'.format(utils.quote_string_if_needed(base_app.editor), - utils.quote_string_if_needed(filename))) + # We think we have an editor, so should expect a Popen call + m.assert_called_once() def test_edit_file_with_spaces(base_app, request, 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) + # Mock out the subprocess.Popen call so we don't actually open an editor + m = mock.MagicMock(name='Popen') + monkeypatch.setattr("subprocess.Popen", m) test_dir = os.path.dirname(request.module.__file__) filename = os.path.join(test_dir, 'my commands.txt') run_cmd(base_app, 'edit "{}"'.format(filename)) - # We think we have an editor, so should expect a system call - m.assert_called_once_with('{} {}'.format(utils.quote_string_if_needed(base_app.editor), - utils.quote_string_if_needed(filename))) + # We think we have an editor, so should expect a Popen call + m.assert_called_once() 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) + # Mock out the subprocess.Popen call so we don't actually open an editor + m = mock.MagicMock(name='Popen') + monkeypatch.setattr("subprocess.Popen", m) run_cmd(base_app, 'edit') - # We have an editor, so should expect a system call + # We have an editor, so should expect a Popen call m.assert_called_once() |