def test_commands_at_invocation(): testargs = ["prog", "say hello", "say Gracie", "quit"] expected = "This is an intro banner ...\nhello\nGracie\n" with mock.patch.object(sys, 'argv', testargs): app = CmdLineApp() app.stdout = StdOut() app.cmdloop() out = app.stdout.buffer assert out == expected
def test_base_cmdloop_with_queue(): # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test app = cmd2.Cmd() app.use_rawinput = True 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 equal to the py.test args testargs = ["prog"] expected = intro + '\n' with mock.patch.object(sys, 'argv', testargs): # Run the command loop with custom intro app.cmdloop(intro=intro) out = app.stdout.buffer assert out == expected
def test_cmdloop_without_rawinput(): # Create a cmd2.Cmd() instance and make sure basic settings are like we want for test app = cmd2.Cmd() app.use_rawinput = False app.intro = 'Hello World, this is an intro ...' app.stdout = StdOut() # Mock out the input call so we don't actually wait for a user's response on stdin m = mock.MagicMock(name='input', return_value='quit') sm.input = m # Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args testargs = ["prog"] expected = app.intro + '\n{}'.format(app.prompt) with mock.patch.object(sys, 'argv', testargs): # Run the command loop app.cmdloop() out = app.stdout.buffer assert out == expected
def _cmdline_app(): c = CmdLineApp() c.stdout = StdOut() return c
def subcommand_app(): app = SubcommandApp() app.stdout = StdOut() return app
def argparse_app(): app = ArgparseApp() app.stdout = StdOut() return app
def _cmdline_app(): c = CmdLineApp() c.stdout = StdOut() #c.shortcuts.update({'&': 'speak', 'h': 'hello'}) c.settable.append('maxrepeats Max number of `--repeat`s allowed') return c
def select_app(): app = SelectApp() app.stdout = StdOut() return app
def help_app(): app = HelpApp() app.stdout = StdOut() return app
def secondlevel_app_b(): app = SecondLevelB() app.stdout = StdOut() return app
def hook_failure(): app = HookFailureApp() app.stdout = StdOut() return app
def abbrev_app(): app = cmd2.Cmd() app.abbrev = True app.stdout = StdOut() return app
def cmdresult_app(): app = CmdResultApp() app.stdout = StdOut() return app
def multiline_app(): app = MultilineApp() app.stdout = StdOut() return app
def noarglist_app(): cmd2.set_use_arg_list(False) app = cmd2.Cmd() app.stdout = StdOut() return app
def _demo_app(): c = DemoApp() c.stdout = StdOut() return c
def shell_app(): app = ShellApp() app.stdout = StdOut() return app
def submenu_app(): app = SubmenuApp() app.stdout = StdOut() second_level_cmd.stdout = StdOut() second_level_b_cmd.stdout = StdOut() return app