From ec2958033283327c671fbd28117336646f5e77c0 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Tue, 9 Jul 2024 11:37:05 +0100 Subject: [PATCH 1/2] fixing charting tests --- .../core/openbb_core/app/model/charts/chart.py | 10 ++-------- .../core/tests/app/model/charts/test_chart.py | 8 ++++---- .../charting/integration/test_charting_api.py | 6 +++++- .../charting/integration/test_charting_python.py | 5 ++++- .../charting/openbb_charting/charting.py | 11 ++++++++--- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/openbb_platform/core/openbb_core/app/model/charts/chart.py b/openbb_platform/core/openbb_core/app/model/charts/chart.py index 38d062d79665..551731cdee87 100644 --- a/openbb_platform/core/openbb_core/app/model/charts/chart.py +++ b/openbb_platform/core/openbb_core/app/model/charts/chart.py @@ -6,12 +6,6 @@ from pydantic import BaseModel, ConfigDict, Field -class ChartFormat(str, Enum): - """Chart format.""" - - plotly = "plotly" - - class Chart(BaseModel): """Model for Chart.""" @@ -19,8 +13,8 @@ class Chart(BaseModel): default=None, description="Raw textual representation of the chart.", ) - format: Optional[ChartFormat] = Field( - default=ChartFormat.plotly, + format: Optional[str] = Field( + default=None, description="Complementary attribute to the `content` attribute. It specifies the format of the chart.", ) fig: Optional[Any] = Field( diff --git a/openbb_platform/core/tests/app/model/charts/test_chart.py b/openbb_platform/core/tests/app/model/charts/test_chart.py index 4f0eb140f42a..0d64ba2e3534 100644 --- a/openbb_platform/core/tests/app/model/charts/test_chart.py +++ b/openbb_platform/core/tests/app/model/charts/test_chart.py @@ -1,7 +1,7 @@ """Test the chart model.""" import pytest -from openbb_core.app.model.charts.chart import Chart, ChartFormat +from openbb_core.app.model.charts.chart import Chart def test_charting_default_values(): @@ -11,14 +11,14 @@ def test_charting_default_values(): # Assert assert chart.content is None - assert chart.format == ChartFormat.plotly + assert chart.format is None def test_charting_custom_values(): """Test the charting custom values.""" # Arrange content = {"data": [1, 2, 3]} - chart_format = ChartFormat.plotly + chart_format = "plotly" # Act chart = Chart(content=content, format=chart_format) @@ -42,7 +42,7 @@ def test_charting_config_validation(): """Test the charting config validation.""" # Arrange content = {"data": [1, 2, 3]} - chart_format = ChartFormat.plotly + chart_format = "plotly" chart = Chart(content=content, format=chart_format) diff --git a/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py b/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py index 7dbd1497eb19..bf94ec046214 100644 --- a/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py +++ b/openbb_platform/obbject_extensions/charting/integration/test_charting_api.py @@ -799,13 +799,17 @@ def test_charting_derivatives_futures_historical(params, headers): ( { "provider": "yfinance", - "symbol": "VX", + "symbol": "ES", + "date": None, + "chart": True, } ), ( { "provider": "cboe", "symbol": "VX", + "date": "2024-06-25", + "chart": True, } ), ], diff --git a/openbb_platform/obbject_extensions/charting/integration/test_charting_python.py b/openbb_platform/obbject_extensions/charting/integration/test_charting_python.py index 277f65ea9fea..673f632be7e4 100644 --- a/openbb_platform/obbject_extensions/charting/integration/test_charting_python.py +++ b/openbb_platform/obbject_extensions/charting/integration/test_charting_python.py @@ -654,7 +654,9 @@ def test_charting_derivatives_futures_historical(params, obb): ( { "provider": "yfinance", - "symbol": "VX", + "symbol": "ES", + "date": None, + "chart": True, } ), ( @@ -662,6 +664,7 @@ def test_charting_derivatives_futures_historical(params, obb): "provider": "cboe", "symbol": "VX", "date": "2024-06-25", + "chart": True, } ), ], diff --git a/openbb_platform/obbject_extensions/charting/openbb_charting/charting.py b/openbb_platform/obbject_extensions/charting/openbb_charting/charting.py index 24ef1bd466fb..4558d9327693 100644 --- a/openbb_platform/obbject_extensions/charting/openbb_charting/charting.py +++ b/openbb_platform/obbject_extensions/charting/openbb_charting/charting.py @@ -64,6 +64,7 @@ class Charting: entry_point.load() for entry_point in entry_points(group="openbb_charting_extension") ] + _format = "plotly" # the charts computed by this extension will be in plotly format def __init__(self, obbject): """Initialize Charting extension.""" @@ -361,7 +362,7 @@ def show(self, render: bool = True, **kwargs): fig, content = charting_function(**kwargs) fig = self._set_chart_style(fig) content = fig.show(external=True, **kwargs).to_plotly_json() - self._obbject.chart = Chart(fig=fig, content=content) + self._obbject.chart = Chart(fig=fig, content=content, format=self._format) if render: fig.show(**kwargs) except Exception: # pylint: disable=W0718 @@ -369,7 +370,9 @@ def show(self, render: bool = True, **kwargs): fig = self.create_line_chart(data=self._obbject.results, render=False, **kwargs) # type: ignore fig = self._set_chart_style(fig) content = fig.show(external=True, **kwargs).to_plotly_json() # type: ignore - self._obbject.chart = Chart(fig=fig, content=content) + self._obbject.chart = Chart( + fig=fig, content=content, format=self._format + ) if render: return fig.show(**kwargs) # type: ignore except Exception as e: @@ -480,7 +483,9 @@ def to_chart( fig = self.create_line_chart(data=data_as_df, render=False, **kwargs) fig = self._set_chart_style(fig) content = fig.show(external=True, **kwargs).to_plotly_json() # type: ignore - self._obbject.chart = Chart(fig=fig, content=content) + self._obbject.chart = Chart( + fig=fig, content=content, format=self._format + ) if render: return fig.show(**kwargs) # type: ignore except Exception as e: # pylint: disable=W0718 From 1cc9e2e793cd4e95460a98d9795e440596527422 Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Tue, 9 Jul 2024 11:43:30 +0100 Subject: [PATCH 2/2] lint --- openbb_platform/core/openbb_core/app/model/charts/chart.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openbb_platform/core/openbb_core/app/model/charts/chart.py b/openbb_platform/core/openbb_core/app/model/charts/chart.py index 551731cdee87..c5166400bf67 100644 --- a/openbb_platform/core/openbb_core/app/model/charts/chart.py +++ b/openbb_platform/core/openbb_core/app/model/charts/chart.py @@ -1,6 +1,5 @@ """OpenBB Core Chart model.""" -from enum import Enum from typing import Any, Dict, Optional from pydantic import BaseModel, ConfigDict, Field