fix charting_service tests

This commit is contained in:
hjoaquim
2023-10-03 18:37:42 +01:00
parent 0394dc7d2f
commit 798b049637
2 changed files with 18 additions and 17 deletions

View File

@@ -187,22 +187,21 @@ class ChartingService(metaclass=SingletonMeta):
"""
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

View File

@@ -272,17 +272,18 @@ def test_get_implemented_charting_functions(
@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 test_to_chart(
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)