Beispiel #1
0
def test_readline_remove_history_item(base_app):
    from cmd2.rl_utils import readline
    assert readline.get_current_history_length() == 0
    readline.add_history('this is a test')
    assert readline.get_current_history_length() == 1
    readline.remove_history_item(0)
    assert readline.get_current_history_length() == 0
Beispiel #2
0
def test_history_populates_readline(hist_file):
    # - create a cmd2 with persistent history
    app = cmd2.Cmd(persistent_history_file=hist_file)
    run_cmd(app, 'help')
    run_cmd(app, 'shortcuts')
    run_cmd(app, 'shortcuts')
    run_cmd(app, 'alias')
    # call the private method which is registered to write history at exit
    app._persist_history()

    # see if history came back
    app = cmd2.Cmd(persistent_history_file=hist_file)
    assert len(app.history) == 4
    assert app.history.get(1).statement.raw == 'help'
    assert app.history.get(2).statement.raw == 'shortcuts'
    assert app.history.get(3).statement.raw == 'shortcuts'
    assert app.history.get(4).statement.raw == 'alias'

    # readline only adds a single entry for multiple sequential identical commands
    # so we check to make sure that cmd2 populated the readline history
    # using the same rules
    from cmd2.rl_utils import readline
    assert readline.get_current_history_length() == 3
    assert readline.get_history_item(1) == 'help'
    assert readline.get_history_item(2) == 'shortcuts'
    assert readline.get_history_item(3) == 'alias'