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