Test params and providers

This commit is contained in:
Igor Radovanovic
2023-09-29 00:04:35 +02:00
parent 74a232c830
commit a92dfa5650
2 changed files with 83 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
"""Test the integration tests."""
from extensions.tests.utils.integration_tests_testers import (
check_missing_integration_test_params,
check_missing_integration_test_providers,
get_module_functions,
get_python_integration_tests,
@@ -13,3 +14,12 @@ def test_python_interface_integration_tests() -> None:
missing_providers = check_missing_integration_test_providers(functions)
assert not missing_providers, "\n".join(missing_providers)
def test_python_interface_integration_test_params() -> None:
"""Test if there are any missing params for integration tests."""
integration_tests = get_python_integration_tests()
functions = get_module_functions(integration_tests)
missing_params = check_missing_integration_test_params(functions)
assert not missing_params, "\n".join(missing_params)

View File

@@ -2,7 +2,7 @@
import importlib.util
import inspect
import os
from typing import Any, Dict, List
from typing import Any, Callable, Dict, List
from extensions.tests.utils.integration_tests_generator import find_extensions
from sdk.core.openbb_core.app.provider_interface import ProviderInterface
@@ -40,13 +40,69 @@ def get_module_functions(module_list: List[Any]) -> Dict[str, Any]:
return functions
def check_missing_integration_test_providers(functions: Dict[str, Any]) -> List[str]:
"""Check if there are any missing providers for integration tests."""
def check_missing_providers(
command_params: Dict[str, Dict[str, dict]],
function_params: List[dict],
function,
) -> List[str]:
"""Check if there are any missing providers for a command."""
missing_providers: List[str] = []
providers = list(command_params.keys())
providers.remove("openbb")
for test_params in function_params:
provider = test_params.get("provider", None)
if provider:
try: # noqa
providers.remove(provider)
except ValueError:
pass
if providers:
# if there is only one provider left and the length of the
# test_params is 1, we can ignore because it is picked up by default
if len(providers) == 1 and len(function_params) == 1:
pass
else:
missing_providers.append(f"Missing providers for {function}: {providers}")
return missing_providers
def check_missing_params(
command_params: Dict[str, Dict[str, dict]], function_params: List[dict], function
) -> List[str]:
"""Check if there are any missing params for a command."""
missing_params = []
for test_params in function_params:
if "provider" in test_params:
provider = test_params["provider"]
if provider in command_params:
for expected_param in command_params[provider]["QueryParams"]["fields"]:
if expected_param not in test_params.keys():
missing_params.append(
f"Missing param {expected_param} for provider {provider} in function {function}"
)
else:
for expected_param in command_params["openbb"]["QueryParams"]["fields"]:
if expected_param not in test_params.keys():
missing_params.append(
f"Missing standard param {expected_param} in function {function}"
)
return missing_params
def check_integration_tests(
functions: Dict[str, Any],
check_function: Callable[[Dict[str, Dict[str, dict]], List[dict], str], List[str]],
) -> List[str]:
"""Check if there are any missing items for integration tests."""
pi = ProviderInterface()
provider_interface_map = pi.map
cm = CommandMap(coverage_sep=".")
missing_providers: List[str] = []
all_missing_items: List[str] = []
for command, model in cm.commands_model.items():
for function in functions:
@@ -56,25 +112,19 @@ def check_missing_integration_test_providers(functions: Dict[str, Any]) -> List[
]
function_params: List[dict] = functions[function].pytestmark[1].args[1]
providers = list(command_params.keys())
providers.remove("openbb")
missing_items = check_function(
command_params, function_params, function
)
all_missing_items.extend(missing_items)
for test_params in function_params:
provider = test_params.get("provider", None)
if provider:
try: # noqa
providers.remove(provider)
except ValueError:
pass
return all_missing_items
if providers:
# if there is only one provider left and the length of the
# test_params is 1, we can ignore because it is picked up by default
if len(providers) == 1 and len(function_params) == 1:
pass
else:
missing_providers.append(
f"Missing providers for {function}: {providers}"
)
return missing_providers
def check_missing_integration_test_providers(functions: Dict[str, Any]) -> List[str]:
"""Check if there are any missing providers for integration tests."""
return check_integration_tests(functions, check_missing_providers)
def check_missing_integration_test_params(functions: Dict[str, Any]) -> List[str]:
"""Check if there are any missing params for integration tests."""
return check_integration_tests(functions, check_missing_params)