From 27a711ba461c8a632feb10efc71b35baddb49bd2 Mon Sep 17 00:00:00 2001 From: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:32:12 +0100 Subject: [PATCH] [Feature] - Create static asset tests (#6182) * Create static asset tests * Lint --- openbb_platform/tests/test_extension_map.py | 6 ++- openbb_platform/tests/test_pyproject_toml.py | 39 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/openbb_platform/tests/test_extension_map.py b/openbb_platform/tests/test_extension_map.py index 2bf082e891d..aa24ace5633 100644 --- a/openbb_platform/tests/test_extension_map.py +++ b/openbb_platform/tests/test_extension_map.py @@ -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" diff --git a/openbb_platform/tests/test_pyproject_toml.py b/openbb_platform/tests/test_pyproject_toml.py index f250dfb2aa0..7012b0797dc 100644 --- a/openbb_platform/tests/test_pyproject_toml.py +++ b/openbb_platform/tests/test_pyproject_toml.py @@ -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"] @@ -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." + )