summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-02-05 12:39:01 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2017-02-05 12:39:01 -0500
commite2a691f47e5f81e3fdbec4af033e0e9f13884108 (patch)
tree6af8708727bbf483e23820b6d1b1153d3fae1feb
parentd5a0487b0058cdf52b295e9ae203e8e90f3247dd (diff)
downloadcmd2-git-e2a691f47e5f81e3fdbec4af033e0e9f13884108.tar.gz
Added unit test for cmdloop()
-rw-r--r--tests/test_cmd2.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index d1906fc4..d352bd4e 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -15,7 +15,7 @@ import six
from code import InteractiveConsole
import cmd2
-from conftest import run_cmd, normalize, BASE_HELP, HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT, SHOW_LONG
+from conftest import run_cmd, normalize, BASE_HELP, HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT, SHOW_LONG, StdOut
def test_ver():
@@ -461,3 +461,21 @@ def test_base_py_interactive(base_app):
# Make sure our mock was called once and only once
m.assert_called_once()
+
+
+def test_base_cmdloop_with_queue(capsys):
+ # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
+ app = cmd2.Cmd()
+ app.use_rawinput = True
+ app.intro = 'Hello World, this is an intro ...'
+ app.cmdqueue.append('quit\n')
+ app.stdout = StdOut()
+
+ # Need to patch sys.argv so cmd2 doesn't think it was called with arguments
+ testargs = ["prog"]
+ expected = app.intro + '\n'
+ with mock.patch.object(sys, 'argv', testargs):
+ # Run the command loop
+ app.cmdloop()
+ out = app.stdout.buffer
+ assert out == expected