mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-06-08 15:54:10 +08:00
[Feature] - Create static asset tests (#6182)
* Create static asset tests * Lint
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user