(mocker, hist_file)
| 728 | |
| 729 | |
| 730 | def 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 | |
| 765 | def test_history_verbose_with_other_options(base_app) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…