Files
OpenBB/cli/tests/test_config_setup.py
Igor Radovanovic a116d9bbf2 [Feature] - OpenBB Platform CLI Unit tests (#6397)
* Unit test batch 1

* CLI controller

* Test batch 3

* Test batch 4

* Test batch 5

* clean some workflows and setup actions

* test

* rename wfs

* rename

* update action

* Skip

* fix cli tests

---------

Co-authored-by: Henrique Joaquim <henriquecjoaquim@gmail.com>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
2024-05-14 15:38:06 +00:00

50 lines
1.7 KiB
Python

"""Test the Config Setup."""
from unittest.mock import patch
import pytest
from openbb_cli.config.setup import bootstrap
# pylint: disable=unused-variable
def test_bootstrap_creates_directory_and_file():
"""Test that bootstrap creates the settings directory and environment file."""
with patch("pathlib.Path.mkdir") as mock_mkdir, patch(
"pathlib.Path.touch"
) as mock_touch:
bootstrap()
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_touch.assert_called_once_with(exist_ok=True)
def test_bootstrap_directory_exists():
"""Test bootstrap when the directory already exists."""
with patch("pathlib.Path.mkdir") as mock_mkdir, patch(
"pathlib.Path.touch"
) as mock_touch:
bootstrap()
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_touch.assert_called_once_with(exist_ok=True)
def test_bootstrap_file_exists():
"""Test bootstrap when the environment file already exists."""
with patch("pathlib.Path.mkdir") as mock_mkdir, patch(
"pathlib.Path.touch"
) as mock_touch:
bootstrap()
mock_mkdir.assert_called_once_with(parents=True, exist_ok=True)
mock_touch.assert_called_once_with(exist_ok=True)
def test_bootstrap_permission_error():
"""Test bootstrap handles permission errors gracefully."""
with patch("pathlib.Path.mkdir") as mock_mkdir, patch(
"pathlib.Path.touch"
) as mock_touch, pytest.raises( # noqa: F841
PermissionError
):
mock_mkdir.side_effect = PermissionError("No permission to create directory")
bootstrap() # Expecting to raise a PermissionError and be caught by pytest.raises