Skip to content

Commit

Permalink
fix charting_service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hjoaquim committed Oct 3, 2023
1 parent 0394dc7 commit 798b049
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
25 changes: 12 additions & 13 deletions openbb_platform/platform/core/openbb_core/app/charting_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions openbb_platform/platform/core/tests/app/test_charting_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 798b049

Please sign in to comment.