mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-25 18:53:26 +00:00
some more tests for models
This commit is contained in:
@@ -26,22 +26,26 @@ class ChartingSettings:
|
||||
|
||||
# System
|
||||
self.log_collect: bool = system_settings.log_collect
|
||||
self.version = system_settings.version
|
||||
self.python_version = system_settings.python_version
|
||||
self.version: str = system_settings.version
|
||||
self.python_version: str = system_settings.python_version
|
||||
self.test_mode = system_settings.test_mode
|
||||
self.app_id: str = get_app_id(user_data_directory)
|
||||
self.debug_mode: bool = system_settings.debug_mode
|
||||
self.headless: bool = system_settings.headless
|
||||
# User
|
||||
self.plot_enable_pywry = user_settings.preferences.plot_enable_pywry
|
||||
self.plot_pywry_width = user_settings.preferences.plot_pywry_width
|
||||
self.plot_pywry_height = user_settings.preferences.plot_pywry_height
|
||||
self.plot_open_export = user_settings.preferences.plot_open_export
|
||||
self.user_email = user_settings.profile.hub_session.email if has_hub else None
|
||||
self.user_uuid = (
|
||||
self.plot_enable_pywry: bool = user_settings.preferences.plot_enable_pywry
|
||||
self.plot_pywry_width: int = user_settings.preferences.plot_pywry_width
|
||||
self.plot_pywry_height: int = user_settings.preferences.plot_pywry_height
|
||||
self.plot_open_export: bool = user_settings.preferences.plot_open_export
|
||||
self.user_email: Optional[str] = (
|
||||
user_settings.profile.hub_session.email if has_hub else None
|
||||
)
|
||||
self.user_uuid: Optional[str] = (
|
||||
user_settings.profile.hub_session.user_uuid if has_hub else None
|
||||
)
|
||||
self.user_exports_directory = user_settings.preferences.export_directory
|
||||
self.user_styles_directory = user_settings.preferences.user_styles_directory
|
||||
self.user_exports_directory: str = user_settings.preferences.export_directory
|
||||
self.user_styles_directory: str = (
|
||||
user_settings.preferences.user_styles_directory
|
||||
)
|
||||
# Theme
|
||||
self.chart_style = user_settings.preferences.chart_style
|
||||
self.chart_style: str = user_settings.preferences.chart_style
|
||||
|
||||
24
openbb_sdk/sdk/core/tests/app/models/abstract/test_error.py
Normal file
24
openbb_sdk/sdk/core/tests/app/models/abstract/test_error.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from openbb_core.app.model.abstract.error import Error
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"error_kind, message",
|
||||
[
|
||||
("test", "test"),
|
||||
("test2", "test2"),
|
||||
],
|
||||
)
|
||||
def test_error_model(error_kind, message):
|
||||
err = Error(error_kind=error_kind, message=message)
|
||||
|
||||
assert err.error_kind == error_kind
|
||||
assert err.message == message
|
||||
|
||||
|
||||
def test_fields():
|
||||
fields = Error.__fields__
|
||||
fields_keys = fields.keys()
|
||||
|
||||
assert "error_kind" in fields_keys
|
||||
assert "message" in fields_keys
|
||||
@@ -0,0 +1,9 @@
|
||||
from openbb_core.app.model.abstract.results import Results
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
def test_results_model():
|
||||
res = Results()
|
||||
|
||||
assert isinstance(res, BaseModel)
|
||||
@@ -0,0 +1,32 @@
|
||||
from openbb_core.app.model.abstract.singleton import SingletonMeta
|
||||
|
||||
|
||||
class MyClass(metaclass=SingletonMeta):
|
||||
def __init__(self, value):
|
||||
self.value = value
|
||||
|
||||
|
||||
def test_singleton_instance_creation():
|
||||
# Arrange
|
||||
instance1 = MyClass(42)
|
||||
instance2 = MyClass(100)
|
||||
|
||||
# Act & Assert
|
||||
assert instance1 is instance2
|
||||
assert instance1.value == instance2.value
|
||||
assert instance1.value == 42
|
||||
|
||||
|
||||
def test_singleton_multiple_classes():
|
||||
# Arrange
|
||||
class AnotherClass(metaclass=SingletonMeta):
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
instance1 = MyClass(42)
|
||||
instance2 = AnotherClass("test")
|
||||
|
||||
# Act & Assert
|
||||
assert instance1 is not instance2
|
||||
assert instance1.value == 42
|
||||
assert instance2.data == "test"
|
||||
14
openbb_sdk/sdk/core/tests/app/models/abstract/test_tagged.py
Normal file
14
openbb_sdk/sdk/core/tests/app/models/abstract/test_tagged.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from openbb_core.app.model.abstract.tagged import Tagged
|
||||
|
||||
|
||||
def test_tagged_model():
|
||||
tagged = Tagged()
|
||||
|
||||
assert hasattr(tagged, "id")
|
||||
|
||||
|
||||
def test_fields():
|
||||
fields = Tagged.__fields__
|
||||
fields_keys = fields.keys()
|
||||
|
||||
assert "id" in fields_keys
|
||||
@@ -0,0 +1,36 @@
|
||||
from openbb_core.app.model.abstract.warning import Warning_, cast_warning
|
||||
|
||||
import pytest
|
||||
from unittest.mock import Mock
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"category, message",
|
||||
[
|
||||
("test", "test"),
|
||||
("test2", "test2"),
|
||||
],
|
||||
)
|
||||
def test_warn_model(category, message):
|
||||
war = Warning_(category=category, message=message)
|
||||
|
||||
assert war.category == category
|
||||
assert war.message == message
|
||||
|
||||
|
||||
def test_fields():
|
||||
fields = Warning_.__fields__
|
||||
fields_keys = fields.keys()
|
||||
|
||||
assert "category" in fields_keys
|
||||
assert "message" in fields_keys
|
||||
|
||||
|
||||
def test_cast_warning():
|
||||
mock_warning_message = Mock()
|
||||
mock_warning_message.category.__name__ = "test"
|
||||
mock_warning_message.message = "test"
|
||||
warning = cast_warning(mock_warning_message)
|
||||
|
||||
assert warning.category == "test"
|
||||
assert warning.message == "test"
|
||||
51
openbb_sdk/sdk/core/tests/app/models/charts/test_chart.py
Normal file
51
openbb_sdk/sdk/core/tests/app/models/charts/test_chart.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from openbb_core.app.model.charts.chart import Chart, ChartFormat, Error
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_chart_default_values():
|
||||
# Arrange & Act
|
||||
chart = Chart()
|
||||
|
||||
# Assert
|
||||
assert chart.content is None
|
||||
assert chart.format == ChartFormat.plotly
|
||||
assert chart.error is None
|
||||
|
||||
|
||||
def test_chart_custom_values():
|
||||
# Arrange
|
||||
content = {"data": [1, 2, 3]}
|
||||
chart_format = ChartFormat.plotly
|
||||
error = Error(message="Test Error")
|
||||
|
||||
# Act
|
||||
chart = Chart(content=content, format=chart_format, error=error)
|
||||
|
||||
# Assert
|
||||
assert chart.content == content
|
||||
assert chart.format == chart_format
|
||||
assert chart.error == error
|
||||
|
||||
|
||||
def test_chart_assignment_validation():
|
||||
# Arrange
|
||||
chart = Chart()
|
||||
|
||||
# Act & Assert
|
||||
with pytest.raises(ValueError):
|
||||
chart.invalid_field = "Invalid Value"
|
||||
|
||||
|
||||
def test_chart_config_validation():
|
||||
# Arrange
|
||||
content = {"data": [1, 2, 3]}
|
||||
chart_format = ChartFormat.plotly
|
||||
|
||||
chart = Chart(content=content, format=chart_format)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
chart.content = "Invalid Content"
|
||||
|
||||
assert chart.content == content
|
||||
assert chart.format == chart_format
|
||||
@@ -0,0 +1,49 @@
|
||||
from openbb_core.app.model.charts.charting_settings import ChartingSettings
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
mock_user_settings = MagicMock()
|
||||
mock_user_settings.preferences.data_directory = "mock_data_directory"
|
||||
mock_user_settings.preferences.plot_enable_pywry = True
|
||||
mock_user_settings.preferences.plot_pywry_width = 100
|
||||
mock_user_settings.preferences.plot_pywry_height = 100
|
||||
mock_user_settings.preferences.plot_open_export = True
|
||||
mock_user_settings.profile.hub_session.email = "mock_email"
|
||||
mock_user_settings.profile.hub_session.user_uuid = "mock_uuid"
|
||||
mock_user_settings.preferences.export_directory = "mock_export_directory"
|
||||
mock_user_settings.preferences.user_styles_directory = "mock_styles_directory"
|
||||
mock_user_settings.preferences.chart_style = "mock_chart_style"
|
||||
|
||||
mock_system_settings = MagicMock()
|
||||
mock_system_settings.log_collect = True
|
||||
mock_system_settings.version = "mock_version"
|
||||
mock_system_settings.python_version = "mock_python_version"
|
||||
mock_system_settings.test_mode = True
|
||||
mock_system_settings.debug_mode = True
|
||||
mock_system_settings.headless = True
|
||||
|
||||
|
||||
def test_charting_settings(mocker):
|
||||
mocker.patch(
|
||||
target="openbb_core.app.model.charts.charting_settings.get_app_id",
|
||||
new=mocker.Mock(return_value="mock_app_id"),
|
||||
)
|
||||
charting_settings = ChartingSettings(
|
||||
user_settings=mock_user_settings, system_settings=mock_system_settings
|
||||
)
|
||||
assert charting_settings.log_collect is True
|
||||
assert charting_settings.version == "mock_version"
|
||||
assert charting_settings.python_version == "mock_python_version"
|
||||
assert charting_settings.test_mode is True
|
||||
assert charting_settings.app_id == "mock_app_id"
|
||||
assert charting_settings.debug_mode is True
|
||||
assert charting_settings.headless is True
|
||||
assert charting_settings.plot_enable_pywry is True
|
||||
assert charting_settings.plot_pywry_width == 100
|
||||
assert charting_settings.plot_pywry_height == 100
|
||||
assert charting_settings.plot_open_export is True
|
||||
assert charting_settings.user_email == "mock_email"
|
||||
assert charting_settings.user_uuid == "mock_uuid"
|
||||
assert charting_settings.user_exports_directory == "mock_export_directory"
|
||||
assert charting_settings.user_styles_directory == "mock_styles_directory"
|
||||
assert charting_settings.chart_style == "mock_chart_style"
|
||||
Reference in New Issue
Block a user