コード例 #1
0
def test_cmd_default(default_command):
    cmd = create_cmd()
    if default_command is not None:
        cmd.default = default_command
    add_comm(cmd)
    add_comm2(cmd)
    add_comm3(cmd)
    cmd.queue("comm")
    cmd.queue("comm2")
    cmd.queue("")
    cmd.queue("quit")
    cmd.run()
    expected_lines = [
        COMM_TEXT,
        COMM_TEXT2,
    ]
    if default_command is IGNORE or default_command is None:
        pass
    elif default_command is REPEAT_LAST:
        expected_lines.append(COMM_TEXT2)
    elif default_command == "comm3":
        expected_lines.append(COMM_TEXT3)
    expected_lines.append("")
    expected_text = '\n'.join(expected_lines)
    #print(cmd.stdout.getvalue())
    #print(repr(cmd.stdout.getvalue()))
    #print()
    #print(repr(expected_text))
    assert cmd.stdout.getvalue() == expected_text
コード例 #2
0
def cmdhis():
    cmd = create_cmd()
    add_comm(cmd)
    add_comm2(cmd)
    add_comm3(cmd)
    add_history(cmd)
    return cmd
コード例 #3
0
def test_cmdx_queue_command0_doc(cmdx):
    doc = "Hi, folk!"
    cmd = create_cmd()
    cmd.doc = doc
    cmd = cmdx(cmd)
    cmd.queue("comm")
    cmd.run()
    debug_cmd(cmd)
    assert cmd.stdout.getvalue() == doc + '\n' + COMM_TEXT + '\n'
コード例 #4
0
def test_ignore():
    cmd = create_cmd()
    add_comm(cmd)
    add_comm2(cmd)
    add_quit(cmd)
    cmd.exec_command_line("comm")
    assert cmd.stdout.getvalue() == COMM_TEXT + '\n'
    assert not IGNORE(cmd)
    cmd.queue("quit")
    cmd.run()
    assert cmd.stdout.getvalue() == COMM_TEXT + '\n'
コード例 #5
0
def test_repeat_last():
    cmd = create_cmd()
    add_comm(cmd)
    add_comm2(cmd)
    add_quit(cmd)
    cmd.exec_command_line("comm")
    assert cmd.stdout.getvalue() == COMM_TEXT + '\n'
    assert not REPEAT_LAST(cmd)
    cmd.queue("quit")
    cmd.run()
    assert cmd.stdout.getvalue() == COMM_TEXT + '\n' + COMM_TEXT + '\n'
コード例 #6
0
def cmd():
    cmd = create_cmd()

    @cmd.command
    def foo(interpreter):
        "This is foo command"
        interpreter.output(TEXT_FOO)
        return False

    @foo.topic
    def fx(interpreter):
        interpreter.output("foo fx")

    _grp = cmd.group(name="grp")

    @_grp.topic
    def gx(interpreter):
        interpreter.output("grp gx")

    @argument("--debug", "-d",
        action="store_true",
        help="enable debug mode")
    @_grp.command
    def bar(interpreter):
        "This is grp.bar command"
        interpreter.output(TEXT_BAR)
        return False

    @_grp.command
    def baz(interpreter):
        "This is grp.baz command"
        interpreter.output(TEXT_BAZ)
        return False

    @baz.document
    def baz(interpreter):
        interpreter.output("baz baz baz")

    @baz.topic(name="by")
    def ay(interpreter):
        interpreter.output("baz by")

    return cmd
コード例 #7
0
def cmd():
    cmd = create_cmd()
    @cmd.command
    def bar(interpreter):
        interpreter.output(TEXT_BAR)
        return False

    @cmd.command
    def baz(interpreter):
        interpreter.output(TEXT_BAZ)
        return False

    @cmd.topic
    def bazbaz(interpreter):
        pass

    grpx = cmd.group("grpx")

    @grpx.command
    def grpx_0(interpreter):
        interpreter.output("grpx_0!")

    subgrpx = grpx.group("subgrpx")

    @subgrpx.command
    def subgrpx_0(interpreter):
        interpreter.output("subgrpx_0!")

    grpy = cmd.group("grpy")

    @grpy.command
    def grpy_0(interpreter):
        interpreter.output("grpy_0!")

    @argument("--name", "-n")
    @cmd.command
    def greet(interpreter, name):
        interpreter.output("Hello, {}!".format(name))
        return False

    return cmd
コード例 #8
0
def test_load(tmpdir):
    cmd = create_cmd()
    add_comm(cmd)
    add_comm2(cmd)
    add_comm3(cmd)
    add_quit(cmd)
    fname = os.path.join(tmpdir.strpath, "load.txt")
    with open(fname, "w") as f_out:
        f_out.write("comm\n")
        f_out.write("comm3\n")
        f_out.write("comm2\n")
        f_out.write("quit\n")
    assert not LOAD(cmd, fname)
    cmd.run()
    expected_lines = [
        COMM_TEXT,
        COMM_TEXT3,
        COMM_TEXT2,
        '',
    ]
    assert cmd.stdout.getvalue() == '\n'.join(expected_lines)
コード例 #9
0
def cmd():
    cmd = create_cmd()
    @cmd.command
    def foo(interpreter):
        interpreter.output("foo!")
        return False

    _bar = cmd.group("bar")

    @_bar.command(name="bar0")
    def bar_0(interpreter):
        interpreter.output("bar.bar0!")

    @_bar.command(name="bar1")
    def bar_1(interpreter):
        interpreter.output("bar.bar1!")

    _bar_sub = _bar.group("sub")

    @_bar_sub.command(name="sub0")
    def bar_sub_sub0(interpreter):
        interpreter.output("bar.sub.sub0!")

    _baz = cmd.group("baz")

    @_baz.command(name="baz0")
    def baz_0(interpreter):
        interpreter.output("baz.baz0!")

    _baz_sub = _baz.group("sub")

    @_baz_sub.command(name="sub0")
    def baz_sub_sub0(interpreter):
        interpreter.output("baz.sub.sub0!")


    return cmd
コード例 #10
0
def test_shell_fail():
    cmd = create_cmd()
    assert not SHELL(cmd, 'non_existent_command')
    assert cmd.stdout.getvalue() == ""
    assert cmd.stderr.getvalue() != ""
コード例 #11
0
def test_shell_ok():
    text = 'Hello, world!'
    cmd = create_cmd()
    assert not SHELL(cmd, 'echo', text)
    assert cmd.stdout.getvalue() == text + '\n'
コード例 #12
0
def test_quit():
    cmd = create_cmd()
    assert QUIT(cmd)
コード例 #13
0
def cmdpy():
    cmd = create_cmd()
    add_py(cmd)
    add_history(cmd)
    return cmd