fix obbject tests

This commit is contained in:
hjoaquim
2024-01-25 12:02:49 +00:00
parent 0e001a398e
commit 1a00fb2ed5
2 changed files with 5 additions and 45 deletions

View File

@@ -267,11 +267,10 @@ class OBBject(Tagged, Generic[T]):
def show(self):
"""Display chart."""
if not self.chart or not hasattr(self.chart, "fig"):
# pylint: disable=no-member
if not self.chart or not self.chart.fig:
raise OpenBBError("Chart not found.")
show_function: Callable = getattr(
self.chart.fig, "show" # pylint: disable=no-member
)
show_function: Callable = getattr(self.chart.fig, "show")
show_function()
@classmethod

View File

@@ -1,5 +1,5 @@
"""Tests for the OBBject class."""
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock
import pandas as pd
import pytest
@@ -320,45 +320,6 @@ def test_to_dict(results, expected_dict):
assert str(exc_info.value) == str(expected_dict)
@patch("openbb_core.app.model.obbject.OBBject.to_dataframe")
@patch("openbb_core.app.charting_service.ChartingService")
def test_to_chart_with_new_chart(
mock_charting_service,
mock_to_dataframe,
):
"""Test helper."""
def get_mock_dataframe():
data = {
"col1": [1, 2, 3],
"col2": ["a", "b", "c"],
"col3": [True, False, True],
}
return pd.DataFrame(data)
# Arrange
mock_instance = OBBject()
mock_charting_service_instance = mock_charting_service.return_value
mock_charting_service_instance.to_chart.return_value = Chart(
content={"content": "some_new_content"}, fig={"fig": "some_mock_fig"}
)
mock_to_dataframe.return_value = get_mock_dataframe()
# Act
result = mock_instance.to_chart()
# Assert
assert result == {"fig": "some_mock_fig"}
assert mock_instance.chart.content == {"content": "some_new_content"}
# Ensure self.to_dataframe() was called
mock_to_dataframe.assert_called_once()
# Ensure ChartingService was called with the correct parameters
mock_charting_service_instance.to_chart.assert_called_once()
def test_show_chart_exists():
"""Test helper."""
mock_instance = OBBject()
@@ -371,7 +332,7 @@ def test_show_chart_exists():
mock_instance.show()
# Assert
mock_instance.chart.fig.show.assert_called_once()
mock_instance.chart.fig.show.assert_called_once() # pylint: disable=no-member
def test_show_chart_no_chart():