mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-05-07 14:31:54 +08:00
* add support for Python 3.14 * escape % in argparse_translator in help strings * black * cli python version string * fix test param placeholder * fix integration_tests_testers * add 3.14 to ODP Desktop environment creation choices * partial lock update * update lock files * and the rest of the locks --------- Co-authored-by: deeleeramone <>
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"Test the Session class."
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from openbb_cli.models.settings import Settings
|
|
from openbb_cli.session import Session, sys
|
|
|
|
# pylint: disable=redefined-outer-name, unused-argument, protected-access
|
|
|
|
|
|
def mock_isatty(return_value):
|
|
"""Mock the isatty method."""
|
|
original_isatty = sys.stdin.isatty
|
|
sys.stdin.isatty = MagicMock(return_value=return_value) # type: ignore
|
|
return original_isatty
|
|
|
|
|
|
@pytest.fixture
|
|
def session():
|
|
"""Session fixture."""
|
|
return Session()
|
|
|
|
|
|
def test_session_initialization(session):
|
|
"""Test the initialization of the Session class."""
|
|
assert session.settings is not None
|
|
assert session.style is not None
|
|
assert session.console is not None
|
|
assert session.obbject_registry is not None
|
|
assert isinstance(session.settings, Settings)
|
|
|
|
|
|
@patch("openbb_cli.session.PromptSession")
|
|
@patch("sys.stdin.isatty", return_value=True)
|
|
def test_get_prompt_session_true(mock_isatty, mock_prompt_session, session):
|
|
"Test get_prompt_session method."
|
|
prompt_session = session._get_prompt_session()
|
|
assert prompt_session is not None
|
|
|
|
|
|
@patch("sys.stdin.isatty", return_value=False)
|
|
def test_get_prompt_session_false(mock_isatty, session):
|
|
"Test get_prompt_session method."
|
|
prompt_session = session._get_prompt_session()
|
|
assert prompt_session is None
|