mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
* fix circular import issues on the obbject extension framework * settings available on the obbject * extension init * charting assets and code * introduce to_chart functionality * removes the to_chart method from obbject in detriment of the one from the obbject extension * Update openbb_platform/obbject_extensions/charting/charting/__init__.py Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> * fix on the show method * adding the example to the to_chart docstring * copying the exsting README from charting extension - needs to be revamped * moving to openbb_charting instead * update the pyproject.toml file * pydocstyle * versions * better docstrings * making accessors public * removing unnecessary credentials variable cc @montezdesousa * removing access to extra/metadata and use designated private attrs instead * Fixes linting for the logging service (#5992) * lints * typing.Type instead * deprecating ChartingService to use the new extension instead - adding function discovery capabilities using it * tests for the obbject charting extension * removing charting service from command runner * filter functions not implemented in the module * remove charting service tests * removing charting service on the tests for int tests * charting integration tests * removing charting service file * removing old charting extension code * revamp builder * fix obbject tests * fix command_runner tests * removing openbb_figure_table * better website docs * reviewed readme * unsetting api key for posthog (pywry) windows * added debug_mode to the system settings * removing api key * update nightly script * fix tests * black * black * Revert "black" This reverts commit21d76ad689. * Revert "black" This reverts commit0904653fd7. * black for henrique * returning a list instead * better docstrings * removing unnecessary indicators docstring * typo * black * intentional access to protected member * changes to publish script * filtering deleted files * black * adding render argument * fixing the df_to_basemodel function: it should include the index in the columns either if flagged or if the index is named * adding the hability to add you own data to to_chart method * tests * black * disable protected access * accept kwargs to eg. save image * adjustment cc Igor * add if statement for protection * remove unused return typing * fix technical charting views * better error message cc @IgorWounds * better structure and fix test * Revert "better structure and fix test" This reverts commit612ea6117c. * Revert "better error message cc @IgorWounds" This reverts commit3d7ee53878. --------- Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com> Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com>
132 lines
3.4 KiB
Python
132 lines
3.4 KiB
Python
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from openbb_charting import Charting
|
|
from openbb_core.app.model.system_settings import SystemSettings
|
|
from openbb_core.app.model.user_settings import UserSettings
|
|
from pydantic import BaseModel
|
|
|
|
|
|
@pytest.fixture()
|
|
def obbject():
|
|
class MockStdParams(BaseModel):
|
|
param1: str
|
|
param2: str
|
|
|
|
class MockOOBject:
|
|
def __init__(self):
|
|
self._user_settings = UserSettings()
|
|
self._system_settings = SystemSettings()
|
|
self._route = "mock/route"
|
|
self._standard_params = MockStdParams(
|
|
param1="mock_param1", param2="mock_param2"
|
|
)
|
|
self.results = "mock_results"
|
|
|
|
def to_dataframe(self):
|
|
return "mock_dataframe"
|
|
|
|
return MockOOBject()
|
|
|
|
|
|
def test_charting_settings(obbject):
|
|
cm = Charting(obbject)
|
|
assert isinstance(cm, Charting)
|
|
|
|
|
|
@patch("openbb_charting.ChartIndicators.get_available_indicators")
|
|
def test_indicators(mock_get_available_indicators, obbject):
|
|
# Arrange
|
|
mock_get_available_indicators.return_value = [
|
|
"indicator1",
|
|
"indicator2",
|
|
"indicator3",
|
|
]
|
|
obj = Charting(obbject)
|
|
|
|
# Act
|
|
result = obj.indicators()
|
|
|
|
# Assert
|
|
assert result == ["indicator1", "indicator2", "indicator3"]
|
|
mock_get_available_indicators.assert_called_once()
|
|
|
|
|
|
@patch("openbb_charting.get_charting_functions")
|
|
def test_functions(mock_get_charting_functions):
|
|
# Arrange
|
|
mock_get_charting_functions.return_value = ["function1", "function2", "function3"]
|
|
|
|
# Act
|
|
result = Charting.functions()
|
|
|
|
# Assert
|
|
assert result == ["function1", "function2", "function3"]
|
|
mock_get_charting_functions.assert_called_once()
|
|
|
|
|
|
@patch("openbb_charting.core.backend.get_backend")
|
|
@patch("openbb_charting.core.backend.create_backend")
|
|
def test_handle_backend(mock_create_backend, mock_get_backend, obbject):
|
|
# Act -> _handle backend is called in the constructor
|
|
obj = Charting(obbject)
|
|
|
|
# Assert
|
|
mock_create_backend.assert_called_once_with(obj._charting_settings)
|
|
mock_get_backend.assert_called_once()
|
|
|
|
|
|
@patch("openbb_charting.charting_router")
|
|
def test_get_chart_function(mock_charting_router):
|
|
# Arrange
|
|
mock_function = MagicMock()
|
|
mock_charting_router.some_function = mock_function
|
|
route = "/some/function"
|
|
|
|
# Act
|
|
result = Charting._get_chart_function(route)
|
|
|
|
# Assert
|
|
assert result == mock_function
|
|
|
|
|
|
@patch("openbb_charting.Charting._get_chart_function")
|
|
def test_show(mock_get_chart_function, obbject):
|
|
# Arrange
|
|
mock_function = MagicMock()
|
|
mock_get_chart_function.return_value = mock_function
|
|
mock_fig = MagicMock()
|
|
mock_function.return_value = (mock_fig, {"content": "mock_content"})
|
|
obj = Charting(obbject)
|
|
|
|
# Act
|
|
obj.show()
|
|
|
|
# Assert
|
|
mock_get_chart_function.assert_called_once()
|
|
mock_function.assert_called_once()
|
|
mock_fig.show.assert_called_once()
|
|
|
|
|
|
@patch("openbb_charting.to_chart")
|
|
def test_to_chart(mock_to_chart, obbject):
|
|
# Arrange
|
|
mock_fig = MagicMock()
|
|
mock_to_chart.return_value = (mock_fig, {"content": "mock_content"})
|
|
obj = Charting(obbject)
|
|
|
|
# Act
|
|
obj.to_chart()
|
|
|
|
# Assert
|
|
assert obj._obbject.chart.fig == mock_fig
|
|
mock_to_chart.assert_called_once_with(
|
|
"mock_dataframe",
|
|
indicators=None,
|
|
symbol="",
|
|
candles=True,
|
|
volume=True,
|
|
prepost=False,
|
|
volume_ticks_x=7,
|
|
)
|