summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-11 17:39:11 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-11 17:39:11 -0400
commit77633bc4498d6f11b07ea0a3bd13d4830f809ff8 (patch)
tree037879fb49353ac66a5d2a3e6c74f0cb3a3b0dd2 /tests
parent1aee0316973873e8967679f6778952c1d696866a (diff)
downloadcmd2-git-77633bc4498d6f11b07ea0a3bd13d4830f809ff8.tar.gz
Removed support for cmd.cmdqueue
allow_cli_args is now an argument to __init__ instead of a cmd2 class member
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py33
-rw-r--r--tests/test_plugin.py16
-rw-r--r--tests/test_transcript.py32
3 files changed, 41 insertions, 40 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 2b7b6578..795efcdb 100644
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -25,13 +25,15 @@ from cmd2 import clipboard, constants, utils
from .conftest import run_cmd, normalize, BASE_HELP, BASE_HELP_VERBOSE, \
HELP_HISTORY, SHORTCUTS_TXT, SHOW_TXT, SHOW_LONG
-
-@pytest.fixture
-def outsim_app():
+def CreateOutsimApp():
c = cmd2.Cmd()
c.stdout = utils.StdSim(c.stdout)
return c
+@pytest.fixture
+def outsim_app():
+ return CreateOutsimApp()
+
def test_version(base_app):
assert cmd2.__version__
@@ -109,9 +111,8 @@ def test_base_show_readonly(base_app):
out, err = run_cmd(base_app, 'set -a')
expected = normalize(SHOW_TXT + '\nRead only settings:' + """
Commands may be terminated with: {}
- Arguments at invocation allowed: {}
Output redirection and pipes allowed: {}
-""".format(base_app.statement_parser.terminators, base_app.allow_cli_args, base_app.allow_redirection))
+""".format(base_app.statement_parser.terminators, base_app.allow_redirection))
assert out == expected
@@ -734,23 +735,26 @@ def test_base_py_interactive(base_app):
m.assert_called_once()
-def test_base_cmdloop_with_queue(outsim_app):
- # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
- outsim_app.use_rawinput = True
+def test_base_cmdloop_with_startup_commands():
intro = 'Hello World, this is an intro ...'
- outsim_app.cmdqueue.append('quit\n')
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
- testargs = ["prog"]
+ testargs = ["prog", 'quit']
expected = intro + '\n'
+
with mock.patch.object(sys, 'argv', testargs):
+ # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
+ app = CreateOutsimApp()
+ app.use_rawinput = True
+
# Run the command loop with custom intro
- outsim_app.cmdloop(intro=intro)
- out = outsim_app.stdout.getvalue()
+ app.cmdloop(intro=intro)
+
+ out = app.stdout.getvalue()
assert out == expected
-def test_base_cmdloop_without_queue(outsim_app):
+def test_base_cmdloop_without_startup_commands(outsim_app):
# Create a cmd2.Cmd() instance and make sure basic settings are like we want for test
outsim_app.use_rawinput = True
outsim_app.intro = 'Hello World, this is an intro ...'
@@ -823,8 +827,7 @@ class SayApp(cmd2.Cmd):
@pytest.fixture
def say_app():
- app = SayApp()
- app.allow_cli_args = False
+ app = SayApp(allow_cli_args=False)
app.stdout = utils.StdSim(app.stdout)
return app
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index d439c123..ce4eac2b 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -264,8 +264,8 @@ def test_register_preloop_hook_with_return_annotation():
def test_preloop_hook(capsys):
app = PluggedApp()
app.register_preloop_hook(app.prepost_hook_one)
- app.cmdqueue.append('say hello')
- app.cmdqueue.append('quit')
+ app._startup_commands.append('say hello')
+ app._startup_commands.append('quit')
app.cmdloop()
out, err = capsys.readouterr()
assert out == 'one\nhello\n'
@@ -275,8 +275,8 @@ def test_preloop_hooks(capsys):
app = PluggedApp()
app.register_preloop_hook(app.prepost_hook_one)
app.register_preloop_hook(app.prepost_hook_two)
- app.cmdqueue.append('say hello')
- app.cmdqueue.append('quit')
+ app._startup_commands.append('say hello')
+ app._startup_commands.append('quit')
app.cmdloop()
out, err = capsys.readouterr()
assert out == 'one\ntwo\nhello\n'
@@ -295,8 +295,8 @@ def test_register_postloop_hook_with_wrong_return_annotation():
def test_postloop_hook(capsys):
app = PluggedApp()
app.register_postloop_hook(app.prepost_hook_one)
- app.cmdqueue.append('say hello')
- app.cmdqueue.append('quit')
+ app._startup_commands.append('say hello')
+ app._startup_commands.append('quit')
app.cmdloop()
out, err = capsys.readouterr()
assert out == 'hello\none\n'
@@ -306,8 +306,8 @@ def test_postloop_hooks(capsys):
app = PluggedApp()
app.register_postloop_hook(app.prepost_hook_one)
app.register_postloop_hook(app.prepost_hook_two)
- app.cmdqueue.append('say hello')
- app.cmdqueue.append('quit')
+ app._startup_commands.append('say hello')
+ app._startup_commands.append('quit')
app.cmdloop()
out, err = capsys.readouterr()
assert out == 'hello\none\ntwo\n'
diff --git a/tests/test_transcript.py b/tests/test_transcript.py
index 4af547b1..214ef87b 100644
--- a/tests/test_transcript.py
+++ b/tests/test_transcript.py
@@ -110,11 +110,6 @@ def test_commands_at_invocation():
('word_boundaries.txt', False),
])
def test_transcript(request, capsys, filename, feedback_to_output):
- # Create a cmd2.Cmd() instance and make sure basic settings are
- # like we want for test
- app = CmdLineApp()
- app.feedback_to_output = feedback_to_output
-
# Get location of the transcript
test_dir = os.path.dirname(request.module.__file__)
transcript_file = os.path.join(test_dir, 'transcripts', filename)
@@ -123,6 +118,11 @@ def test_transcript(request, capsys, filename, feedback_to_output):
# arguments equal to the py.test args
testargs = ['prog', '-t', transcript_file]
with mock.patch.object(sys, 'argv', testargs):
+ # Create a cmd2.Cmd() instance and make sure basic settings are
+ # like we want for test
+ app = CmdLineApp()
+ app.feedback_to_output = feedback_to_output
+
# Run the command loop
sys_exit_code = app.cmdloop()
assert sys_exit_code == 0
@@ -192,7 +192,6 @@ def test_load_record_transcript(base_app, request):
test_dir = os.path.dirname(request.module.__file__)
filename = os.path.join(test_dir, 'scripts', 'help.txt')
- assert base_app.cmdqueue == []
assert base_app._script_dir == []
assert base_app._current_script_dir is None
@@ -203,7 +202,6 @@ def test_load_record_transcript(base_app, request):
# Run the load command with the -r option to generate a transcript
run_cmd(base_app, 'load {} -t {}'.format(filename, transcript_fname))
- assert base_app.cmdqueue == []
assert base_app._script_dir == []
assert base_app._current_script_dir is None
@@ -271,11 +269,6 @@ def test_parse_transcript_expected(expected, transformed):
def test_transcript_failure(request, capsys):
- # Create a cmd2.Cmd() instance and make sure basic settings are
- # like we want for test
- app = CmdLineApp()
- app.feedback_to_output = False
-
# Get location of the transcript
test_dir = os.path.dirname(request.module.__file__)
transcript_file = os.path.join(test_dir, 'transcripts', 'failure.txt')
@@ -284,6 +277,11 @@ def test_transcript_failure(request, capsys):
# arguments equal to the py.test args
testargs = ['prog', '-t', transcript_file]
with mock.patch.object(sys, 'argv', testargs):
+ # Create a cmd2.Cmd() instance and make sure basic settings are
+ # like we want for test
+ app = CmdLineApp()
+ app.feedback_to_output = False
+
# Run the command loop
sys_exit_code = app.cmdloop()
assert sys_exit_code != 0
@@ -296,15 +294,15 @@ def test_transcript_failure(request, capsys):
def test_transcript_no_file(request, capsys):
- # Create a cmd2.Cmd() instance and make sure basic settings are
- # like we want for test
- app = CmdLineApp()
- app.feedback_to_output = False
-
# Need to patch sys.argv so cmd2 doesn't think it was called with
# arguments equal to the py.test args
testargs = ['prog', '-t']
with mock.patch.object(sys, 'argv', testargs):
+ # Create a cmd2.Cmd() instance and make sure basic settings are
+ # like we want for test
+ app = CmdLineApp()
+ app.feedback_to_output = False
+
# Run the command loop
sys_exit_code = app.cmdloop()
assert sys_exit_code != 0