@@ -28,19 +28,25 @@ def verify_hi_last_result(app: cmd2.Cmd, expected_length: int) -> None:
2828
2929
3030#
31- # readline tests
31+ # prompt-toolkit tests
3232#
33- def test_readline_remove_history_item () -> None :
34- from cmd2 .rl_utils import (
35- readline ,
36- )
33+ def test_pt_add_history_item () -> None :
34+ from prompt_toolkit import PromptSession
35+ from prompt_toolkit .history import InMemoryHistory
36+
37+ # Create a history object and add some initial items
38+ history = InMemoryHistory ()
39+ history .append_string ('command one' )
40+ history .append_string ('command two' )
41+ assert 'command one' in history .get_strings ()
42+ assert len (history .get_strings ()) == 2
43+
44+ # Start a session and use this history
45+ session = PromptSession (history = history )
3746
38- readline .clear_history ()
39- assert readline .get_current_history_length () == 0
40- readline .add_history ('this is a test' )
41- assert readline .get_current_history_length () == 1
42- readline .remove_history_item (0 )
43- assert readline .get_current_history_length () == 0
47+ session .history .get_strings ().append ('new command' )
48+ assert 'new command' not in session .history .get_strings ()
49+ assert len (history .get_strings ()) == 2
4450
4551
4652#
@@ -949,7 +955,7 @@ def test_history_file_bad_json(mocker, capsys) -> None:
949955 assert 'Error processing persistent history data' in err
950956
951957
952- def test_history_populates_readline (hist_file ) -> None :
958+ def test_history_populates_pt (hist_file ) -> None :
953959 # - create a cmd2 with persistent history
954960 app = cmd2 .Cmd (persistent_history_file = hist_file )
955961 run_cmd (app , 'help' )
@@ -967,17 +973,14 @@ def test_history_populates_readline(hist_file) -> None:
967973 assert app .history .get (3 ).statement .raw == 'shortcuts'
968974 assert app .history .get (4 ).statement .raw == 'alias'
969975
970- # readline only adds a single entry for multiple sequential identical commands
976+ # prompt-toolkit only adds a single entry for multiple sequential identical commands
971977 # so we check to make sure that cmd2 populated the readline history
972978 # using the same rules
973- from cmd2 .rl_utils import (
974- readline ,
975- )
976-
977- assert readline .get_current_history_length () == 3
978- assert readline .get_history_item (1 ) == 'help'
979- assert readline .get_history_item (2 ) == 'shortcuts'
980- assert readline .get_history_item (3 ) == 'alias'
979+ pt_history = app .session .history .get_strings ()
980+ assert len (pt_history ) == 3
981+ assert pt_history .get (1 ) == 'help'
982+ assert pt_history .get (2 ) == 'shortcuts'
983+ assert pt_history .get (3 ) == 'alias'
981984
982985
983986#
0 commit comments