mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
* Fixes * Update stocks_helper.py * update git-actions set-output to new format * Update stocks_helper.py * Update terminal_helper.py * removed LineAnnotateDrawer from qa_view * lint * few changes * updates * sdk auto gen modules done * Update stocks_helper.py * updates to changed imports, and remove first sdk_modules * Update generate_sdk.py * Update generate_sdk.py * pylint * revert stocks_helper * Update generate_sdk.py * Update sdk.py * Update generate_sdk.py * full auto generation, added sdk.py/controllers creation * missed enable forecasting * added running black in subprocess after sdk files generation completes * removed deleted sdk_arg_logger * comment out tests * property doc fix * clean up * Update generate_sdk.py * make trailmap classes useable for doc generation * Update generate_sdk.py * added lineon to trailmap class for linking to func in markdown * changed lineon to dict * added full_path to trailmap for linking in docs * updated portfolio * feat: initial files * feat: added meta head * feat: added funcdef * added func_def to trailmap attributes for markdown in docs, added missing type hints to covid functions * feat: added view and merged with jaun * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * init * fix returns * fix: random stuff * fix: random * fixed encoding issue on windows * fix: generate tabs * update * Update generate_sdk_markdown.py * Create .pydocstyle.ini * added type hint classes for views * fixes * alt, ba * alt-economy * Update finviz_compare_model.py * fixs * Update substack_model.py * Update generate_sdk.py * last of my section * porfolio * po * Update optimizer_model.py * fixing more things * few more * keys done * update * fixes * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * mypy forecast fix * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * fixes * forecast fixes * one more fix * Update coinbase_model.py * Update generate_sdk_markdown.py Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: jose-donato <zmcdonato@gmail.com> Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
from typing import Optional, List, Tuple
|
|
from inspect import signature
|
|
import pytest
|
|
|
|
# Certain openbb distributions like pip do not include the docs folder,
|
|
# this is needed for those tests
|
|
try:
|
|
from docs.generate import all_functions
|
|
except ImportError:
|
|
pytest.skip(allow_module_level=True)
|
|
|
|
|
|
# A dictionary where keys are bad parameter names and values are the correct replacements
|
|
bad_params = {
|
|
"ticker": "symbol",
|
|
"descend": "ascend",
|
|
"descending": "ascend",
|
|
"ascending": "ascend",
|
|
"num": "limit",
|
|
"sort_by": "sortby",
|
|
"start": "start_date",
|
|
"end": "end_date",
|
|
"df": "data",
|
|
"x": "independent_series",
|
|
"y": "dependent_series",
|
|
"expire": "expiry",
|
|
"exp": "expiry",
|
|
"expiration": "expiry",
|
|
"vs": "to_symbol",
|
|
"coin": "symbol",
|
|
"coin_id": "symbol",
|
|
"token": "symbol",
|
|
"currency": "symbol",
|
|
"country_code": "country",
|
|
"sort_col": "sortby",
|
|
"sort_field": "sortby",
|
|
"num_tickers": "limit",
|
|
"num_stocks": "limit",
|
|
"since": "start_date",
|
|
"until": "end_date",
|
|
"top": "limit",
|
|
}
|
|
|
|
|
|
def create_overlaps(
|
|
overlaps: List[str], func_name: str, func_path: str
|
|
) -> Optional[Tuple[List[str], str, str, str]]:
|
|
"""
|
|
Checks if there is a bad parameter name in a function
|
|
|
|
Parameters
|
|
----------
|
|
overlaps : List[str]
|
|
Any overlaps between forbidden parameters and the function's parameters
|
|
func_name: str
|
|
The name of the function
|
|
func_path: str
|
|
The path for the function
|
|
|
|
Returns
|
|
-------
|
|
overlaps: Optional[Tuple[List[str], str, str, str]]
|
|
Tuple[overlaps, func_name, func_path, overlaps_str]
|
|
"""
|
|
if overlaps:
|
|
overlap_str = "\n"
|
|
for item in overlaps:
|
|
overlap_str += f"{item}->{bad_params[item]}\n"
|
|
return overlaps, func_name, func_path, overlap_str
|
|
return None
|
|
|
|
|
|
def test_bad_parameters():
|
|
all_funcs = all_functions()
|
|
total_overlaps = 0
|
|
all_overlaps: List[Tuple[List[str], str, str, str]] = []
|
|
for path, _, function in all_funcs:
|
|
params = signature(function)
|
|
overlaps = list(set(bad_params) & set(params.parameters.keys()))
|
|
new_overlaps = create_overlaps(overlaps, function.__name__, path)
|
|
if new_overlaps:
|
|
total_overlaps += 1
|
|
all_overlaps.append(new_overlaps)
|
|
final_str = ""
|
|
if all_overlaps:
|
|
for overlaps, func_name, func_path, overlap_str in all_overlaps:
|
|
final_str += (
|
|
f"Forbidden parameter{'s' if len(overlaps) > 1 else ''} in function"
|
|
f" '{func_name}' at {func_path}. Replace the following: {overlap_str}\n\n"
|
|
)
|
|
|
|
final_str += f"\n\nTotal bad functions: {total_overlaps}"
|
|
raise NameError(final_str)
|