From 798b0496371643012e1e90dbd3d12df0f34ffa2e Mon Sep 17 00:00:00 2001 From: hjoaquim Date: Tue, 3 Oct 2023 18:37:42 +0100 Subject: [PATCH] fix charting_service tests --- .../core/openbb_core/app/charting_service.py | 25 +++++++++---------- .../core/tests/app/test_charting_service.py | 10 +++++--- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/openbb_platform/platform/core/openbb_core/app/charting_service.py b/openbb_platform/platform/core/openbb_core/app/charting_service.py index c7fc8d75e66e..13a8d80999e0 100644 --- a/openbb_platform/platform/core/openbb_core/app/charting_service.py +++ b/openbb_platform/platform/core/openbb_core/app/charting_service.py @@ -187,22 +187,21 @@ def get_implemented_charting_functions( """ Given an extension name, it returns the implemented charting functions from its router. """ + implemented_functions = [] try: - module = cls._get_extension_router(extension_name) + if module := cls._get_extension_router(extension_name): + module_name = module.__name__ + + for name, obj in getmembers(module, isfunction): + if ( + obj.__module__ == module_name + and not name.startswith("_") + and "NotImplementedError" not in getsource(obj) + ): + implemented_functions.append(name) except ChartingServiceError: - return [] - - implemented_functions = [] - module_name = module.__name__ - - for name, obj in getmembers(module, isfunction): - if ( - obj.__module__ == module_name - and not name.startswith("_") - and "NotImplementedError" not in getsource(obj) - ): - implemented_functions.append(name) + pass return implemented_functions diff --git a/openbb_platform/platform/core/tests/app/test_charting_service.py b/openbb_platform/platform/core/tests/app/test_charting_service.py index 0f054cd5b97e..3b1354a756fc 100644 --- a/openbb_platform/platform/core/tests/app/test_charting_service.py +++ b/openbb_platform/platform/core/tests/app/test_charting_service.py @@ -272,17 +272,18 @@ def ta_ema(self): @pytest.mark.parametrize( - "charting_extension_installed, expected_result", - [(True, ...), (False, ChartingServiceError)], + "charting_extension_installed", + [(True), (False)], ) @patch("openbb_core.app.charting_service.ChartingService._handle_backend") @patch("openbb_core.app.charting_service.import_module") +@patch("openbb_core.app.charting_service.ChartingService._get_chart_format") def test_to_chart( + mock_get_chart_format, mock_import_module, mock_handle_backend, charting_service, charting_extension_installed, - expected_result, ): charting_service._charting_extension_installed = charting_extension_installed @@ -294,8 +295,9 @@ def to_chart(**kwargs): return ("mock_fig", {"content": "mock_content"}) mock_import_module.return_value = MockBackendModule() + mock_get_chart_format.return_value = "plotly" - if expected_result != ChartingServiceError: + if charting_extension_installed: result = charting_service.to_chart() assert isinstance(result, Chart)