From 42acf57cc2ae887b3b3474473e3330fd635f8ced Mon Sep 17 00:00:00 2001 From: Diogo Sousa Date: Thu, 2 Feb 2023 13:02:37 +0000 Subject: [PATCH] test remove cli hist file --- .../session/test_local_model.py | 27 +++++++++++++++++++ ...test_remove_cli_history_file_exception.txt | 2 ++ 2 files changed, 29 insertions(+) create mode 100644 tests/openbb_terminal/session/txt/test_local_model/test_remove_cli_history_file_exception.txt diff --git a/tests/openbb_terminal/session/test_local_model.py b/tests/openbb_terminal/session/test_local_model.py index 1344885bc67..449b06089a8 100644 --- a/tests/openbb_terminal/session/test_local_model.py +++ b/tests/openbb_terminal/session/test_local_model.py @@ -96,3 +96,30 @@ def test_remove_session_file_exception(): os_mock.path.isfile.assert_called_with(local_model.SESSION_FILE_PATH) os_mock.remove.assert_called_with(local_model.SESSION_FILE_PATH) + + +def test_remove_cli_history_file(): + with patch("openbb_terminal.session.local_model.os") as os_mock: + assert local_model.remove_cli_history_file() is True + + os_mock.path.isfile.assert_called_with(local_model.HIST_FILE_PATH) + os_mock.remove.assert_called_with(local_model.HIST_FILE_PATH) + + +def test_remove_cli_history_file_not_exist(): + with patch("openbb_terminal.session.local_model.os") as os_mock: + os_mock.path.isfile.return_value = False + assert local_model.remove_cli_history_file() is True + + os_mock.path.isfile.assert_called_with(local_model.HIST_FILE_PATH) + os_mock.remove.assert_not_called() + + +@pytest.mark.record_stdout +def test_remove_cli_history_file_exception(): + with patch("openbb_terminal.session.local_model.os") as os_mock: + os_mock.remove.side_effect = Exception + assert local_model.remove_cli_history_file() is False + + os_mock.path.isfile.assert_called_with(local_model.HIST_FILE_PATH) + os_mock.remove.assert_called_with(local_model.HIST_FILE_PATH) diff --git a/tests/openbb_terminal/session/txt/test_local_model/test_remove_cli_history_file_exception.txt b/tests/openbb_terminal/session/txt/test_local_model/test_remove_cli_history_file_exception.txt new file mode 100644 index 00000000000..436ae6e20dd --- /dev/null +++ b/tests/openbb_terminal/session/txt/test_local_model/test_remove_cli_history_file_exception.txt @@ -0,0 +1,2 @@ + +[red]Failed to remove terminal history file.[/red]