Ejemplo n.º 1
0
def hist():
    from cmd2.parsing import Statement
    from cmd2.cmd2 import History, HistoryItem
    h = History([HistoryItem(Statement('', raw='first'), 1),
                 HistoryItem(Statement('', raw='second'), 2),
                 HistoryItem(Statement('', raw='third'), 3),
                 HistoryItem(Statement('', raw='fourth'),4)])
    return h
Ejemplo n.º 2
0
def hist():
    from cmd2.cmd2 import (
        History,
        HistoryItem,
    )
    from cmd2.parsing import (
        Statement, )

    h = History([
        HistoryItem(Statement('', raw='first')),
        HistoryItem(Statement('', raw='second')),
        HistoryItem(Statement('', raw='third')),
        HistoryItem(Statement('', raw='fourth')),
    ])
    return h
Ejemplo n.º 3
0
def test_statement_as_dict(parser):
    # Make sure to_dict() results can be restored to identical Statement
    statement = parser.parse("!ls > out.txt")
    assert statement == Statement.from_dict(statement.to_dict())

    statement = parser.parse("!ls | grep text")
    assert statement == Statement.from_dict(statement.to_dict())

    statement = parser.parse("multiline arg; suffix")
    assert statement == Statement.from_dict(statement.to_dict())

    # from_dict() should raise KeyError if required field is missing
    statement = parser.parse("command")
    statement_dict = statement.to_dict()
    del statement_dict[Statement._args_field]

    with pytest.raises(KeyError):
        Statement.from_dict(statement_dict)
Ejemplo n.º 4
0
def histitem():
    from cmd2.parsing import Statement
    from cmd2.history import HistoryItem
    statement = Statement('history',
                            raw='help history',
                            command='help',
                            arg_list=['history'],
                            )
    histitem = HistoryItem(statement, 1)
    return histitem
Ejemplo n.º 5
0
def test_history_item_instantiate():
    from cmd2.history import (
        HistoryItem, )
    from cmd2.parsing import (
        Statement, )

    statement = Statement(
        'history',
        raw='help history',
        command='help',
        arg_list=['history'],
    )
    with pytest.raises(TypeError):
        _ = HistoryItem()
Ejemplo n.º 6
0
def test_history_item_instantiate():
    from cmd2.parsing import Statement
    from cmd2.history import HistoryItem
    statement = Statement('history',
                            raw='help history',
                            command='help',
                            arg_list=['history'],
                            )
    with pytest.raises(TypeError):
        _ = HistoryItem()
    with pytest.raises(TypeError):
        _ = HistoryItem(idx=1)
    with pytest.raises(TypeError):
        _ = HistoryItem(statement=statement)
    with pytest.raises(TypeError):
        _ = HistoryItem(statement=statement, idx='hi')
Ejemplo n.º 7
0
def persisted_hist():
    from cmd2.parsing import Statement
    from cmd2.cmd2 import History, HistoryItem
    h = History([HistoryItem(Statement('', raw='first'), 1),
                 HistoryItem(Statement('', raw='second'), 2),
                 HistoryItem(Statement('', raw='third'), 3),
                 HistoryItem(Statement('', raw='fourth'),4)])
    h.start_session()
    h.append(Statement('', raw='fifth'))
    h.append(Statement('', raw='sixth'))
    return h