Files
OpenBB/openbb_platform/tests/test_extension_map.py
Henrique Joaquim 4400cd9a8f Merge provider and core into core (#5774)
* small changes - moving provider inside the core

* uptade readme

* lint

* remove old provider readme

* leftovers

* refactor website examples

* ruff

* fix nox

* relock

* fix fails_to_deliver headers

* fix for tests that have renamed endpoints

* fix discovery

* removed test for renamed endpoint

* fix broken syntax - test_search_financial_attributes

* fix cash/income/balance

* fix derivatives tests

* fix etf tests

* fix news tests

* fix regulators

* black

* wrong test param

* sort equity gainers/losers by percent

* platform markdown generation import

* Hotfix/fix int tests core merge (#5779)

* removing tests on old endpoint

* removing visualization on old endpoint

* fixing equity tests

* fixing examples

* fix news tests

* fix index test

* example

* add comments

* example

---------

Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
Co-authored-by: Pratyush Shukla <ps4534@nyu.edu>
2023-11-22 13:48:01 +00:00

63 lines
2.2 KiB
Python

import json
from pathlib import Path
from typing import Dict
import pytest
from poetry.core.constraints.version import Version, VersionConstraint, parse_constraint
from poetry.core.pyproject.toml import PyProjectTOML
def load_ext_map(file: Path) -> Dict[str, Version]:
"""Load the extension map from extension_map.json."""
ext_map = {}
with open(file) as f:
ext_map_json = json.load(f)
for _, v in ext_map_json.items():
for value in v:
name, version = value.split("@")
ext_map[name] = Version.parse(version)
return ext_map
def load_req_ext(file: Path) -> Dict[str, VersionConstraint]:
"""Load the required extensions from pyproject.toml."""
pyproject = PyProjectTOML(file)
deps = pyproject.data["tool"]["poetry"]["dependencies"]
req_ext = {}
for k, v in deps.items():
if k.startswith("openbb-") and k not in ("openbb-core"):
name = k[7:]
if isinstance(v, str):
req_ext[name] = parse_constraint(v)
elif isinstance(v, dict) and not v.get("optional", False):
req_ext[name] = parse_constraint(v["version"])
return req_ext
@pytest.mark.skip(
reason="Need to figure out how to test static with different extension bundles"
)
def test_extension_map():
"""Ensure only required extensions are built and versions respect pyproject.toml"""
this_dir = Path(__file__).parent
ext_map = load_ext_map(
Path(this_dir, "..", "openbb", "package", "extension_map.json")
)
req_ext = load_req_ext(Path(this_dir, "..", "pyproject.toml"))
for ext in req_ext:
assert ext in ext_map, (
f"Extension '{ext}' is required in pyproject.toml but is not built, install"
" it and rebuild or remove it from mandatory requirements in pyproject.toml"
)
for name, version in ext_map.items():
assert name in req_ext, (
f"'{name}' is not a required extension in pyproject.toml, uninstall it and"
" rebuild or add it to pyproject.toml"
)
assert req_ext[name].allows(version), (
f"Version '{version}' of extension '{name}' is not compatible with the"
f" version '{req_ext[name]}' constraint in pyproject.toml"
)