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

[Feature] - Create static asset tests #6182

Merged
merged 2 commits into from
Mar 11, 2024
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
6 changes: 4 additions & 2 deletions openbb_platform/tests/test_extension_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ def test_extension_map():
)

for name, version in ext_map.items():
if name not in req_ext:
continue
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"
Expand Down
39 changes: 39 additions & 0 deletions openbb_platform/tests/test_pyproject_toml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
"""Test the pyproject.toml file for consistency and its dependencies."""

import glob
import os

import toml


def test_optional_packages():
"""Ensure only required extensions are built and versions respect pyproject.toml"""
data = toml.load("openbb_platform/pyproject.toml")
dependencies = data["tool"]["poetry"]["dependencies"]
extras = data["tool"]["poetry"]["extras"]
Expand All @@ -22,3 +28,36 @@ def test_optional_packages():

# assert that there is no overlap between default and optional packages
assert set(default_packages).isdisjoint(set(optional_packages))


def test_default_package_files():
"""Ensure only required extensions are built and versions respect pyproject.toml"""
data = toml.load("openbb_platform/pyproject.toml")
dependencies = data["tool"]["poetry"]["dependencies"]
package_files = glob.glob("openbb_platform/openbb/package/*.py")

invalid_packages = []
default_packages = []

for package, details in dependencies.items():
if isinstance(details, dict) is False:
default_packages.append(package)

for file_path in package_files:
package_name = os.path.basename(file_path).replace(".py", "")
if package_name.startswith("_"):
continue
if "_" in package_name:
base_package = package_name.split("_")[0]
if "openbb-" + base_package not in default_packages:
invalid_packages.append(package_name)
elif "openbb-" + package_name not in default_packages:
invalid_packages.append(package_name)

assert not invalid_packages, (
f"If not making a PR, ignore this error -> "
f"Found non-required extension static assets: {invalid_packages}. "
f"Only required packages should be committed."
f"Please create a new environment with only required extensions, "
f"rebuild the static assets, and commit the changes."
)
Loading