mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 20:42:26 +00:00
* stash some changes * add more robust testing * mypy * point PR at V5 * introduce spec file * codespell * test fix * fix workflow environment setup * fix workflow environment setup * fix workflow environment setup * add pyyaml to dependencies * split lint jobs * fix workflow environment setup * fix workflow environment setup * workflow env setup * workflow env setup * clean up code comments * add auth hook entrypoints * codespell * add codegen feature * codespell * move _unpack into dispatchers for consistency with codegen packages * surface nested models in the response * fix missing coverage in CI * socrata updates * test fix * detect plotly output * add --include and --exclude flags from generate-extension command * cap test matrix at python 3.14 * no useless comments * platform controller command description split * merge URL overloads from path params * exclude none and unset from model dump --------- Co-authored-by: deeleeramone <> Co-authored-by: Copilot <copilot@github.com>
87 lines
2.6 KiB
Python
87 lines
2.6 KiB
Python
"""Tests for openbb_cli.codegen.provider_gen — provider __init__.py emission."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
|
|
from openbb_cli.codegen import provider_gen as pg
|
|
|
|
|
|
@dataclass
|
|
class _Fetcher:
|
|
module_name: str
|
|
fetcher_class: str
|
|
model_name: str
|
|
credentials_used: list[str] = field(default_factory=list)
|
|
|
|
|
|
def test_generate_provider_module_emits_provider_block_and_fetcher_imports():
|
|
fetchers = [
|
|
_Fetcher(
|
|
module_name="equity_price_historical",
|
|
fetcher_class="EquityPriceHistoricalFetcher",
|
|
model_name="EquityPriceHistorical",
|
|
credentials_used=["api_key"],
|
|
),
|
|
_Fetcher(
|
|
module_name="equity_quote",
|
|
fetcher_class="EquityQuoteFetcher",
|
|
model_name="EquityQuote",
|
|
credentials_used=["api_key", "app_token"],
|
|
),
|
|
]
|
|
out = pg.generate_provider_module(
|
|
package_name="openbb_codegen",
|
|
provider_name="fmp",
|
|
description="FMP provider.",
|
|
website="https://fmp.example",
|
|
fetchers=fetchers,
|
|
)
|
|
|
|
assert isinstance(out, pg.GeneratedProvider)
|
|
assert out.package_name == "openbb_codegen"
|
|
assert out.provider_name == "fmp"
|
|
# Credentials union deduped + sorted
|
|
assert out.credential_keys == ["api_key", "app_token"]
|
|
|
|
src = out.source
|
|
assert (
|
|
"from openbb_codegen.providers.fmp.models.equity_price_historical "
|
|
"import EquityPriceHistoricalFetcher"
|
|
) in src
|
|
assert (
|
|
"from openbb_codegen.providers.fmp.models.equity_quote import EquityQuoteFetcher"
|
|
) in src
|
|
assert "fmp_provider = Provider(" in src
|
|
assert 'name="fmp"' in src
|
|
assert "description='FMP provider.'" in src
|
|
assert 'website="https://fmp.example"' in src
|
|
assert '"EquityPriceHistorical": EquityPriceHistoricalFetcher,' in src
|
|
assert '"EquityQuote": EquityQuoteFetcher,' in src
|
|
# Credentials block present in sorted order
|
|
assert "credentials=[" in src
|
|
assert "'api_key'" in src
|
|
assert "'app_token'" in src
|
|
|
|
|
|
def test_generate_provider_module_omits_credentials_when_none():
|
|
fetchers = [
|
|
_Fetcher(
|
|
module_name="m",
|
|
fetcher_class="MFetcher",
|
|
model_name="M",
|
|
credentials_used=[],
|
|
)
|
|
]
|
|
out = pg.generate_provider_module(
|
|
package_name="openbb_x",
|
|
provider_name="p",
|
|
description="d",
|
|
website="https://x",
|
|
fetchers=fetchers,
|
|
)
|
|
|
|
assert out.credential_keys == []
|
|
assert "credentials=" not in out.source
|
|
assert "p_provider = Provider(" in out.source
|