mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[Feature] Remove Python 3.9 (#7235)
* remove python 3.9 support and code * black * more cli lint * more linting * more lint * fix for tests * docstring grammar police * add lock to to build function to avoid async import race conditions * grammar police * lots more linting * relock
This commit is contained in:
@@ -40,7 +40,7 @@ def test_add_cmd(menu_text):
|
||||
|
||||
def test_format_cmd_name(menu_text):
|
||||
"""Test formatting of command names that are too long."""
|
||||
long_name = "x" * 50 # Assuming CMD_NAME_LENGTH is 23
|
||||
long_name = "x" * 75 # Assuming CMD_NAME_LENGTH is 65
|
||||
formatted_name = menu_text._format_cmd_name(long_name)
|
||||
assert len(formatted_name) <= menu_text.CMD_NAME_LENGTH
|
||||
assert menu_text.warnings # Check that a warning was added
|
||||
|
||||
@@ -10,9 +10,10 @@ from openbb_cli.config.setup import bootstrap
|
||||
|
||||
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:
|
||||
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)
|
||||
@@ -20,9 +21,10 @@ def test_bootstrap_creates_directory_and_file():
|
||||
|
||||
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:
|
||||
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)
|
||||
@@ -30,9 +32,10 @@ def test_bootstrap_directory_exists():
|
||||
|
||||
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:
|
||||
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)
|
||||
@@ -40,10 +43,10 @@ def test_bootstrap_file_exists():
|
||||
|
||||
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
|
||||
with (
|
||||
patch("pathlib.Path.mkdir") as mock_mkdir,
|
||||
patch("pathlib.Path.touch"),
|
||||
pytest.raises(PermissionError),
|
||||
):
|
||||
mock_mkdir.side_effect = PermissionError("No permission to create directory")
|
||||
bootstrap() # Expecting to raise a PermissionError and be caught by pytest.raises
|
||||
|
||||
@@ -8,7 +8,7 @@ from openbb_cli.controllers.base_controller import BaseController
|
||||
# pylint: disable=unused-argument, unused-variable
|
||||
|
||||
|
||||
class TestableBaseController(BaseController):
|
||||
class DummyBaseController(BaseController):
|
||||
"""Testable Base Controller."""
|
||||
|
||||
def __init__(self, queue=None):
|
||||
@@ -22,14 +22,14 @@ class TestableBaseController(BaseController):
|
||||
|
||||
def test_base_controller_initialization():
|
||||
"""Test the initialization of the base controller."""
|
||||
with patch.object(TestableBaseController, "check_path", return_value=None):
|
||||
controller = TestableBaseController()
|
||||
with patch.object(DummyBaseController, "check_path", return_value=None):
|
||||
controller = DummyBaseController()
|
||||
assert controller.path == ["valid", "path"] # Checking for correct path split
|
||||
|
||||
|
||||
def test_path_validation():
|
||||
"""Test the path validation method."""
|
||||
controller = TestableBaseController()
|
||||
controller = DummyBaseController()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
controller.PATH = "invalid/path"
|
||||
@@ -48,7 +48,7 @@ def test_path_validation():
|
||||
|
||||
def test_parse_input():
|
||||
"""Test the parse input method."""
|
||||
controller = TestableBaseController()
|
||||
controller = DummyBaseController()
|
||||
input_str = "cmd1/cmd2/cmd3"
|
||||
expected = ["cmd1", "cmd2", "cmd3"]
|
||||
result = controller.parse_input(input_str)
|
||||
@@ -57,7 +57,7 @@ def test_parse_input():
|
||||
|
||||
def test_switch():
|
||||
"""Test the switch method."""
|
||||
controller = TestableBaseController()
|
||||
controller = DummyBaseController()
|
||||
with patch.object(controller, "call_exit", MagicMock()) as mock_exit:
|
||||
controller.queue = ["exit"]
|
||||
controller.switch("exit")
|
||||
@@ -66,14 +66,14 @@ def test_switch():
|
||||
|
||||
def test_call_help():
|
||||
"""Test the call help method."""
|
||||
controller = TestableBaseController()
|
||||
controller = DummyBaseController()
|
||||
with patch("openbb_cli.controllers.base_controller.session.console.print"):
|
||||
controller.call_help(None)
|
||||
|
||||
|
||||
def test_call_exit():
|
||||
"""Test the call exit method."""
|
||||
controller = TestableBaseController()
|
||||
controller = DummyBaseController()
|
||||
with patch.object(controller, "save_class", MagicMock()):
|
||||
controller.queue = ["quit"]
|
||||
controller.call_exit(None)
|
||||
|
||||
@@ -41,17 +41,20 @@ def test_remove_file_existing_file():
|
||||
|
||||
def test_remove_file_directory():
|
||||
"""Test removing a directory."""
|
||||
with patch("os.path.isfile", return_value=False), patch(
|
||||
"os.path.isdir", return_value=True
|
||||
), patch("shutil.rmtree") as mock_rmtree:
|
||||
with (
|
||||
patch("os.path.isfile", return_value=False),
|
||||
patch("os.path.isdir", return_value=True),
|
||||
patch("shutil.rmtree") as mock_rmtree,
|
||||
):
|
||||
assert remove_file(Path("/path/to/directory"))
|
||||
mock_rmtree.assert_called_once()
|
||||
|
||||
|
||||
def test_remove_file_failure(mock_session):
|
||||
"""Test removing a file that fails."""
|
||||
with patch("os.path.isfile", return_value=True), patch(
|
||||
"os.remove", side_effect=Exception("Error")
|
||||
with (
|
||||
patch("os.path.isfile", return_value=True),
|
||||
patch("os.remove", side_effect=Exception("Error")),
|
||||
):
|
||||
assert not remove_file(Path("/path/to/file"))
|
||||
mock_session.console.print.assert_called()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"Test the Session class."
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
Reference in New Issue
Block a user