better structure and fix test

This commit is contained in:
hjoaquim
2024-02-14 14:54:35 +00:00
parent 3d7ee53878
commit 612ea6117c
3 changed files with 17 additions and 35 deletions

View File

@@ -1,12 +1,12 @@
"""OpenBB OBBject extension for charting."""
from inspect import getmembers, getsource, isfunction
from typing import (
Any,
Callable,
Dict,
List,
Optional,
Tuple,
Union,
)
@@ -18,8 +18,7 @@ from openbb_core.app.utils import basemodel_to_df, convert_to_basemodel
from openbb_core.provider.abstract.data import Data
from openbb_charting import charting_router
from openbb_charting.core.to_chart import ChartIndicators, OpenBBFigure, to_chart
from openbb_charting.utils.helpers import get_charting_functions
from openbb_charting.core.to_chart import ChartIndicators, to_chart
ext = Extension(name="charting")
@@ -60,9 +59,19 @@ class Charting:
return ChartIndicators.get_available_indicators()
@classmethod
def functions(cls):
def functions(cls) -> List[str]:
"""Returns a list of the available functions."""
return get_charting_functions()
implemented_functions = []
for name, obj in getmembers(charting_router, isfunction):
if (
obj.__module__ == charting_router.__name__
and not name.startswith("_")
and "NotImplementedError" not in getsource(obj)
):
implemented_functions.append(name)
return implemented_functions
def _handle_backend(self):
# pylint: disable=import-outside-toplevel

View File

@@ -1,21 +0,0 @@
"""Helper functions for charting."""
from inspect import getmembers, getsource, isfunction
from typing import List
from openbb_charting import charting_router
def get_charting_functions() -> List[str]:
"""Discover charting functions."""
implemented_functions = []
for name, obj in getmembers(charting_router, isfunction):
if (
obj.__module__ == charting_router.__name__
and not name.startswith("_")
and "NotImplementedError" not in getsource(obj)
):
implemented_functions.append(name)
return implemented_functions

View File

@@ -52,17 +52,11 @@ def test_indicators(mock_get_available_indicators, obbject):
mock_get_available_indicators.assert_called_once()
@patch("openbb_charting.get_charting_functions")
def test_functions(mock_get_charting_functions):
# Arrange
mock_get_charting_functions.return_value = ["function1", "function2", "function3"]
# Act
def test_functions():
"""Smoke test for the functions method."""
result = Charting.functions()
# Assert
assert result == ["function1", "function2", "function3"]
mock_get_charting_functions.assert_called_once()
assert result
@patch("openbb_charting.core.backend.get_backend")