Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test docstrings #5613

Merged
merged 9 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"openbb_platform/tests",
"openbb_platform/platform",
"openbb_platform/providers",
"openbb_platform/extensions",
]


Expand Down
2 changes: 1 addition & 1 deletion openbb_platform/extensions/ta/openbb_ta/ta_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ def kc(
--------
>>> from openbb import obb
>>> stock_data = obb.stocks.load(symbol="TSLA", start_date="2023-01-01", provider="fmp")
>>> kc_data = obb.ta.kc(data=stock_data.results, length=20, scalar=20, ma_mode="ema", offset=0)
>>> kc_data = obb.ta.kc(data=stock_data.results, length=20, scalar=20, mamode="ema", offset=0)
"""

df = basemodel_to_df(data, index=index)
Expand Down
10 changes: 10 additions & 0 deletions openbb_platform/integration/test_docstring_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Test utils."""
import pytest
from integration.utils.helpers import check_docstring_examples


@pytest.mark.integration
def test_docstring_examples():
"""Test that the docstring examples execute without errors."""
errors = check_docstring_examples()
assert not errors, "\n".join(errors)
70 changes: 70 additions & 0 deletions openbb_platform/integration/utils/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""Test helpers."""
import doctest
import glob
import importlib
import logging
import os
from typing import Dict, List

logging.basicConfig(level=logging.INFO)


def get_packages_info() -> Dict[str, str]:
"""Get the paths and names of all the static packages."""
paths_and_names: Dict[str, str] = {}
package_paths = glob.glob("openbb_platform/openbb/package/*.py")
for path in package_paths:
name = os.path.basename(path).split(".")[0]
paths_and_names[path] = name

paths_and_names = {
path: name for path, name in paths_and_names.items() if not name.startswith("_")
}
return paths_and_names


def execute_docstring_examples(
module_name: str, file_path: str, verbose: bool = False
) -> List[str]:
"""Execute the docstring examples of a module."""
errors = []
module_name = f"openbb.package.{module_name}"
module = importlib.import_module(module_name)
examples = doctest.DocTestFinder().find(module)

def execute_script(script, source_info):
try:
local_namespace = {}
exec( # noqa: S102 pylint: disable=exec-used
script, local_namespace, local_namespace
)
if verbose:
logging.info("Executed a test from %s", source_info)
except Exception as e:
errors.append(
f"An exception occurred while executing script from {source_info} - {str(e)}"
)

for example in examples:
script_lines = []

for test in example.examples:
script_lines.append(test.source)

script_content = "".join(script_lines)
execute_script(script_content, file_path)

return errors


def check_docstring_examples() -> List[str]:
"""Test that the docstring examples execute without errors."""
errors = []
paths_and_names = get_packages_info()

for path, name in paths_and_names.items():
result = execute_docstring_examples(name, path, verbose=True)
if result:
errors.extend(result)

return errors
57 changes: 25 additions & 32 deletions openbb_platform/openbb/package/__extensions__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###


from openbb_core.app.static.container import Container
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
import openbb_provider
import pandas
import datetime
import pydantic
from pydantic import BaseModel
from inspect import Parameter
import typing
from typing import List, Dict, Union, Optional, Literal
from annotated_types import Ge, Le, Gt, Lt
import typing_extensions
from openbb_core.app.utils import df_to_basemodel
from openbb_core.app.static.decorators import validate

from openbb_core.app.static.filters import filter_inputs

from openbb_provider.abstract.data import Data


class Extensions(Container):
Expand All @@ -37,20 +20,30 @@ class Extensions(Container):
/ta

Extensions:
- crypto@0.1.0a3
- economy@0.1.0a3
- fixedincome@0.1.0a3
- forex@0.1.0a3
- news@0.1.0a3
- stocks@0.1.0a3

- alpha_vantage@0.1.0a3
- benzinga@0.1.0a3
- fmp@0.1.0a3
- fred@0.1.0a3
- intrinio@0.1.0a3
- tradingeconomics@0.1.0a3
"""
- crypto@0.1.0a4
- econometrics@0.1.0a4
- economy@0.1.0a4
- fixedincome@0.1.0a4
- forex@0.1.0a4
- futures@0.1.0a4
- news@0.1.0a4
- openbb_charting@0.1.0a4
- qa@0.1.0a4
- stocks@0.1.0a4
- ta@0.1.0a4

- alpha_vantage@0.1.0a4
- benzinga@0.1.0a4
- biztoc@0.1.0a4
- cboe@0.1.0a4
- fmp@0.1.0a4
- fred@0.1.0a4
- intrinio@0.1.0a4
- oecd@0.1.0a4
- polygon@0.1.0a4
- quandl@0.1.0a4
- tradingeconomics@0.1.0a4
- yfinance@0.1.0a4 """
# fmt: on
def __repr__(self) -> str:
return self.__doc__ or ""
Expand Down
22 changes: 5 additions & 17 deletions openbb_platform/openbb/package/crypto.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###

from openbb_core.app.static.container import Container
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
import openbb_provider
import pandas
import datetime
import pydantic
from pydantic import BaseModel
from inspect import Parameter
import typing
from typing import List, Dict, Union, Optional, Literal
from annotated_types import Ge, Le, Gt, Lt
from typing import List, Literal, Union

import typing_extensions
from openbb_core.app.utils import df_to_basemodel
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.static.container import Container
from openbb_core.app.static.decorators import validate

from openbb_core.app.static.filters import filter_inputs

from openbb_provider.abstract.data import Data
import openbb_core.app.model.command_context
import openbb_core.app.model.obbject
import types


class ROUTER_crypto(Container):
Expand Down
98 changes: 42 additions & 56 deletions openbb_platform/openbb/package/economy.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
### THIS FILE IS AUTO-GENERATED. DO NOT EDIT. ###

from openbb_core.app.static.container import Container
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
import openbb_provider
import pandas
import datetime
import pydantic
from pydantic import BaseModel
from inspect import Parameter
import typing
from typing import List, Dict, Union, Optional, Literal
from annotated_types import Ge, Le, Gt, Lt
from typing import List, Literal, Union

import typing_extensions
from openbb_core.app.utils import df_to_basemodel
from openbb_core.app.model.custom_parameter import OpenBBCustomParameter
from openbb_core.app.model.obbject import OBBject
from openbb_core.app.static.container import Container
from openbb_core.app.static.decorators import validate

from openbb_core.app.static.filters import filter_inputs

from openbb_provider.abstract.data import Data
import openbb_core.app.model.command_context
import openbb_core.app.model.obbject
import types


class ROUTER_economy(Container):
Expand Down Expand Up @@ -441,13 +429,13 @@ def cpi(
units: typing_extensions.Annotated[
Literal["growth_previous", "growth_same", "index_2015"],
OpenBBCustomParameter(
description="The unit of measurement for the CPI data.\n Options:\n - `growth_previous`: growth from the previous period\n - `growth_same`: growth from the same period in the previous year\n - `index_2015`: index with base year 2015."
description="The unit of measurement for the data.\n Options:\n - `growth_previous`: growth from the previous period\n - `growth_same`: growth from the same period in the previous year\n - `index_2015`: index with base year 2015."
),
] = "growth_same",
frequency: typing_extensions.Annotated[
Literal["monthly", "quarter", "annual"],
OpenBBCustomParameter(
description="The frequency of the data points; options include `monthly`, `quarter`, and `annual`"
description="The frequency of the data.\n Options: `monthly`, `quarter`, and `annual`."
),
] = "monthly",
harmonized: typing_extensions.Annotated[
Expand Down Expand Up @@ -478,13 +466,14 @@ def cpi(
countries : List[Literal['australia', 'austria', 'belgium', 'brazil', 'bulgar...
The country or countries to get data.
units : Literal['growth_previous', 'growth_same', 'index_2015']
The unit of measurement for the CPI data.
The unit of measurement for the data.
Options:
- `growth_previous`: growth from the previous period
- `growth_same`: growth from the same period in the previous year
- `index_2015`: index with base year 2015.
frequency : Literal['monthly', 'quarter', 'annual']
The frequency of the data points; options include `monthly`, `quarter`, and `annual`
The frequency of the data.
Options: `monthly`, `quarter`, and `annual`.
harmonized : bool
Whether you wish to obtain harmonized data.
start_date : Union[datetime.date, None]
Expand Down Expand Up @@ -557,24 +546,29 @@ def econcal(
),
] = None,
importance: typing_extensions.Annotated[
Literal["Low", "Medium", "High"],
OpenBBCustomParameter(description="Importance of the event."),
] = None,
Literal[1, 2, 3],
OpenBBCustomParameter(
description="Importance of the event. (1-Low, 2-Medium, 3-High)"
),
] = 3,
group: typing_extensions.Annotated[
Literal[
"interest rate",
"inflation",
"bonds",
"consumer",
"gdp",
"government",
"housing",
"labour",
"markets",
"money",
"prices",
"trade",
"business",
Union[
Literal[
"interest rate",
"inflation",
"bonds",
"consumer",
"gdp",
"government",
"housing",
"labour",
"markets",
"money",
"prices",
"trade",
"business",
],
None,
],
OpenBBCustomParameter(description="Grouping of events"),
] = None,
Expand All @@ -593,9 +587,9 @@ def econcal(
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None]
End date of the data, in YYYY-MM-DD format.
importance : Literal['Low', 'Medium', 'High']
Importance of the event.
group : Literal['interest rate', 'inflation', 'bonds', 'consumer', 'gdp', 'gover...
importance : Literal[1, 2, 3]
Importance of the event. (1-Low, 2-Medium, 3-High)
group : Union[Literal['interest rate', 'inflation', 'bonds', 'consumer', ...
Grouping of events
country : Union[List[str], str, None]
Country of the event
Expand Down Expand Up @@ -654,7 +648,7 @@ def econcal(
Example
-------
>>> from openbb import obb
>>> obb.economy.econcal()
>>> obb.economy.econcal(importance=3)
""" # noqa: E501

inputs = filter_inputs(
Expand Down Expand Up @@ -747,7 +741,7 @@ def european_index(
Example
-------
>>> from openbb import obb
>>> obb.economy.european_index(symbol="SPX")
>>> obb.economy.european_index(symbol="BUKBUS")
""" # noqa: E501

inputs = filter_inputs(
Expand Down Expand Up @@ -838,7 +832,7 @@ def european_index_constituents(
Example
-------
>>> from openbb import obb
>>> obb.economy.european_index_constituents(symbol="SPX")
>>> obb.economy.european_index_constituents(symbol="BUKBUS")
""" # noqa: E501

inputs = filter_inputs(
Expand Down Expand Up @@ -1048,7 +1042,7 @@ def gdpnom(
units: typing_extensions.Annotated[
Literal["usd", "usd_cap"],
OpenBBCustomParameter(
description="The unit of measurement for the CPI data.\n Options:\n - `growth_previous`: growth from the previous period\n - `growth_same`: growth from the same period in the previous year\n - `index_2015`: index with base year 2015. Units to get nominal GDP in. Either usd or usd_cap indicating per capita."
description="The unit of measurement for the data. Units to get nominal GDP in. Either usd or usd_cap indicating per capita."
),
] = "usd",
start_date: typing_extensions.Annotated[
Expand All @@ -1071,11 +1065,7 @@ def gdpnom(
Parameters
----------
units : Literal['usd', 'usd_cap']
The unit of measurement for the CPI data.
Options:
- `growth_previous`: growth from the previous period
- `growth_same`: growth from the same period in the previous year
- `index_2015`: index with base year 2015. Units to get nominal GDP in. Either usd or usd_cap indicating per capita.
The unit of measurement for the data. Units to get nominal GDP in. Either usd or usd_cap indicating per capita.
start_date : Union[datetime.date, None]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None]
Expand Down Expand Up @@ -1137,7 +1127,7 @@ def gdpreal(
units: typing_extensions.Annotated[
Literal["idx", "qoq", "yoy"],
OpenBBCustomParameter(
description="The unit of measurement for the CPI data.\n Options:\n - `growth_previous`: growth from the previous period\n - `growth_same`: growth from the same period in the previous year\n - `index_2015`: index with base year 2015. Either idx (indicating 2015=100), qoq (previous period) or yoy (same period, previous year).)"
description="The unit of measurement for the data. Either idx (indicating 2015=100), qoq (previous period) or yoy (same period, previous year).)"
),
] = "yoy",
start_date: typing_extensions.Annotated[
Expand All @@ -1160,11 +1150,7 @@ def gdpreal(
Parameters
----------
units : Literal['idx', 'qoq', 'yoy']
The unit of measurement for the CPI data.
Options:
- `growth_previous`: growth from the previous period
- `growth_same`: growth from the same period in the previous year
- `index_2015`: index with base year 2015. Either idx (indicating 2015=100), qoq (previous period) or yoy (same period, previous year).)
The unit of measurement for the data. Either idx (indicating 2015=100), qoq (previous period) or yoy (same period, previous year).)
start_date : Union[datetime.date, None]
Start date of the data, in YYYY-MM-DD format.
end_date : Union[datetime.date, None]
Expand Down
Loading
Loading