Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
def _cmdline_app():
    c = CmdLineApp()
    c.stdout = StdOut()
    return c
Esempio n. 5
0
def subcommand_app():
    app = SubcommandApp()
    app.stdout = StdOut()
    return app
Esempio n. 6
0
def argparse_app():
    app = ArgparseApp()
    app.stdout = StdOut()
    return app
Esempio n. 7
0
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
Esempio n. 8
0
def select_app():
    app = SelectApp()
    app.stdout = StdOut()
    return app
Esempio n. 9
0
def help_app():
    app = HelpApp()
    app.stdout = StdOut()
    return app
Esempio n. 10
0
def secondlevel_app_b():
    app = SecondLevelB()
    app.stdout = StdOut()
    return app
Esempio n. 11
0
def hook_failure():
    app = HookFailureApp()
    app.stdout = StdOut()
    return app
Esempio n. 12
0
def abbrev_app():
    app = cmd2.Cmd()
    app.abbrev = True
    app.stdout = StdOut()
    return app
Esempio n. 13
0
def cmdresult_app():
    app = CmdResultApp()
    app.stdout = StdOut()
    return app
Esempio n. 14
0
def multiline_app():
    app = MultilineApp()
    app.stdout = StdOut()
    return app
Esempio n. 15
0
def noarglist_app():
    cmd2.set_use_arg_list(False)
    app = cmd2.Cmd()
    app.stdout = StdOut()
    return app
Esempio n. 16
0
def _demo_app():
    c = DemoApp()
    c.stdout = StdOut()
    return c
Esempio n. 17
0
def shell_app():
    app = ShellApp()
    app.stdout = StdOut()
    return app
Esempio n. 18
0
def submenu_app():
    app = SubmenuApp()
    app.stdout = StdOut()
    second_level_cmd.stdout = StdOut()
    second_level_b_cmd.stdout = StdOut()
    return app