MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / test_history_clear

Function test_history_clear

tests/test_history.py:730–762  ·  view source on GitHub ↗
(mocker, hist_file)

Source from the content-addressed store, hash-verified

728
729
730def test_history_clear(mocker, hist_file) -> None:
731 # Add commands to history
732 app = cmd2.Cmd(persistent_history_file=hist_file)
733 run_cmd(app, "help")
734 run_cmd(app, "alias")
735
736 # Make sure history has items
737 out, err = run_cmd(app, "history")
738 assert out
739 verify_hi_last_result(app, 2)
740
741 # Clear the history
742 run_cmd(app, "history --clear")
743 assert app.last_result is True
744
745 # Make sure history is empty and its file is gone
746 out, err = run_cmd(app, "history")
747 assert out == []
748 assert not os.path.exists(hist_file)
749 verify_hi_last_result(app, 0)
750
751 # Clear the history again and make sure the FileNotFoundError from trying to delete missing history file is silent
752 run_cmd(app, "history --clear")
753 assert app.last_result is True
754
755 # Cause os.remove to fail and make sure error gets printed
756 mock_remove = mocker.patch("os.remove")
757 mock_remove.side_effect = OSError
758
759 out, err = run_cmd(app, "history --clear")
760 assert out == []
761 assert "Error removing history file" in err[0]
762 assert app.last_result is False
763
764
765def test_history_verbose_with_other_options(base_app) -> None:

Callers

nothing calls this directly

Calls 2

run_cmdFunction · 0.85
verify_hi_last_resultFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…