diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-29 11:21:49 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-01-29 11:21:49 -0500 |
commit | 0e70f0621273dd5f98aa5fffc42a5cb56f97c760 (patch) | |
tree | e6ccbe7d55be0e464ee48ae6857e835eb7192411 /tests/test_history.py | |
parent | 7f76e23221677376bc3676094b6136bb5a259c52 (diff) | |
download | cmd2-git-0e70f0621273dd5f98aa5fffc42a5cb56f97c760.tar.gz |
Printing error when OSError other than FileNotFoundError occurs when deleting persistent history file with history --clear command.
Diffstat (limited to 'tests/test_history.py')
-rwxr-xr-x | tests/test_history.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/test_history.py b/tests/test_history.py index ac8c6cb6..3021109c 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -520,7 +520,7 @@ def test_history_run_one_command(base_app): out2, err2 = run_cmd(base_app, 'history -r 1') assert out1 == out2 -def test_history_clear(hist_file): +def test_history_clear(mocker, hist_file): # Add commands to history app = cmd2.Cmd(persistent_history_file=hist_file) run_cmd(app, 'help') @@ -538,6 +538,17 @@ def test_history_clear(hist_file): assert out == [] assert not os.path.exists(hist_file) + # Clear the history again and make sure the FileNotFoundError from trying to delete missing history file is silent + run_cmd(app, 'history --clear') + + # Cause os.remove to fail and make sure error gets printed + mock_remove = mocker.patch('os.remove') + mock_remove.side_effect = OSError + + out, err = run_cmd(app, 'history --clear') + assert out == [] + assert 'Error removing history file' in err[0] + def test_history_verbose_with_other_options(base_app): # make sure -v shows a usage error if any other options are present options_to_test = ['-r', '-e', '-o file', '-t file', '-c', '-x'] |