Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Charting Integration Tests #6569

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions openbb_platform/core/openbb_core/app/model/charts/chart.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
"""OpenBB Core Chart model."""

from enum import Enum
from typing import Any, Dict, Optional

from pydantic import BaseModel, ConfigDict, Field


class ChartFormat(str, Enum):
"""Chart format."""

plotly = "plotly"


class Chart(BaseModel):
"""Model for Chart."""

content: Optional[Dict[str, Any]] = Field(
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(
Expand Down
8 changes: 4 additions & 4 deletions openbb_platform/core/tests/app/model/charts/test_chart.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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)
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,17 @@ def test_charting_derivatives_futures_historical(params, obb):
(
{
"provider": "yfinance",
"symbol": "VX",
"symbol": "ES",
"date": None,
"chart": True,
}
),
(
{
"provider": "cboe",
"symbol": "VX",
"date": "2024-06-25",
"chart": True,
}
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -361,15 +362,17 @@ 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
try:
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:
Expand Down Expand Up @@ -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
Expand Down
Loading