From 1a00fb2ed57830f9afe4f2e7883c20827187ca2c Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Thu, 25 Jan 2024 12:02:49 +0000 Subject: [PATCH] fix obbject tests --- .../core/openbb_core/app/model/obbject.py | 7 ++- .../core/tests/app/model/test_obbject.py | 43 +------------------ 2 files changed, 5 insertions(+), 45 deletions(-) diff --git a/openbb_platform/core/openbb_core/app/model/obbject.py b/openbb_platform/core/openbb_core/app/model/obbject.py index 5d8b2e09889..104a8977cd1 100644 --- a/openbb_platform/core/openbb_core/app/model/obbject.py +++ b/openbb_platform/core/openbb_core/app/model/obbject.py @@ -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 diff --git a/openbb_platform/core/tests/app/model/test_obbject.py b/openbb_platform/core/tests/app/model/test_obbject.py index ec7ac75b1aa..b8b4b009986 100644 --- a/openbb_platform/core/tests/app/model/test_obbject.py +++ b/openbb_platform/core/tests/app/model/test_obbject.py @@ -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():