Merge branch 'develop' into feature/general_fixes

This commit is contained in:
Diogo Sousa
2023-11-23 13:08:08 +00:00
86 changed files with 1155 additions and 1044 deletions

View File

@@ -11,11 +11,13 @@ from openbb_core.app.logs.handlers_manager import (
class MockPosthogHandler(logging.NullHandler):
def __init__(self, settings):
self.settings = settings
self.level = logging.DEBUG
class MockPathTrackingFileHandler(logging.NullHandler):
def __init__(self, settings):
self.settings = settings
self.level = logging.DEBUG
class MockFormatterWithExceptions(logging.Formatter):

View File

@@ -290,7 +290,7 @@ def test_command_runner_run(_):
@patch("openbb_core.app.command_runner.CommandMap.get_command")
@patch("openbb_core.app.command_runner.StaticCommandRunner._execute_func")
def test_static_command_runner_run(
async def test_static_command_runner_run(
mock_execute_func, mock_get_command, execution_context
):
"""Test static command runner run."""
@@ -308,7 +308,7 @@ def test_static_command_runner_run(
mock_get_command.return_value = other_mock_func
mock_execute_func.return_value = MockOBBject(results=[1, 2, 3, 4])
result = StaticCommandRunner.run(execution_context, 1, 2, c=3, d=4)
result = await StaticCommandRunner.run(execution_context, 1, 2, c=3, d=4)
assert result.results == [1, 2, 3, 4]
assert hasattr(result, "extra")
@@ -319,7 +319,7 @@ def test_static_command_runner_run(
@patch("openbb_core.app.command_runner.ParametersBuilder.build")
@patch("openbb_core.app.command_runner.StaticCommandRunner._command")
@patch("openbb_core.app.command_runner.StaticCommandRunner._chart")
def test_static_command_runner_execute_func(
async def test_static_command_runner_execute_func(
mock_chart,
mock_command,
mock_parameters_builder_build,
@@ -348,7 +348,7 @@ def test_static_command_runner_execute_func(
mock_command.return_value = MockOBBject(results=[1, 2, 3, 4])
mock_chart.return_value = None
result = StaticCommandRunner._execute_func(
result = await StaticCommandRunner._execute_func(
"mock/route", (1, 2, 3, 4), execution_context, mock_func, {}
)
@@ -385,7 +385,7 @@ def test_static_command_runner_chart(mock_charting_service_chart, execution_cont
assert mock_obbject.chart == {"mock": "chart"}
def test_static_command_runner_command():
async def test_static_command_runner_command():
"""Test command."""
class MockOBBject:
@@ -406,7 +406,7 @@ def test_static_command_runner_command():
mock_provider_choices = MockProviderChoices(provider="mock_provider")
result = StaticCommandRunner._command(
result = await StaticCommandRunner._command(
func=other_mock_func,
kwargs={"provider_choices": mock_provider_choices},
)

View File

@@ -93,7 +93,7 @@ def test_check_reserved_param(command_validator):
def test_check_parameters(command_validator):
"""Test check_parameters."""
def func():
async def func():
pass
assert command_validator.check_parameters(func) is None
@@ -105,7 +105,7 @@ def test_check_return_error(command_validator):
"""Test check_return fail."""
with pytest.raises(TypeError):
def func():
async def func():
pass
command_validator.check_return(func)
@@ -114,7 +114,7 @@ def test_check_return_error(command_validator):
def test_check_return(command_validator):
"""Test check_return."""
def valid_function() -> OBBject[Optional[List[int]]]:
async def valid_function() -> OBBject[Optional[List[int]]]:
return OBBject(results=[1, 2, 3])
assert command_validator.check_return(valid_function) is None
@@ -123,7 +123,7 @@ def test_check_return(command_validator):
def test_check(command_validator):
"""Test check."""
def valid_function() -> OBBject[Optional[List[int]]]:
async def valid_function() -> OBBject[Optional[List[int]]]:
return OBBject(results=[1, 2, 3])
assert command_validator.check(valid_function) is None
@@ -144,7 +144,7 @@ def test_command(router):
"""Test command."""
@router.command
def valid_function() -> OBBject[Optional[List[int]]]:
async def valid_function() -> OBBject[Optional[List[int]]]:
return OBBject(results=[1, 2, 3])
assert valid_function
@@ -186,7 +186,7 @@ def test_signature_inspector_init(signature_inspector):
def test_complete_signature(signature_inspector):
"""Test complete_signature."""
def sample_function(
async def sample_function(
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
@@ -202,7 +202,7 @@ def test_complete_signature(signature_inspector):
def test_complete_signature_error(signature_inspector):
"""Test complete_signature."""
def valid_function() -> OBBject[Optional[List[int]]]:
async def valid_function() -> OBBject[Optional[List[int]]]:
return OBBject(results=[1, 2, 3])
assert (
@@ -213,7 +213,7 @@ def test_complete_signature_error(signature_inspector):
def test_validate_signature(signature_inspector):
"""Test validate_signature."""
def sample_function( # type: ignore
async def sample_function( # type: ignore
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
@@ -237,7 +237,7 @@ def test_validate_signature(signature_inspector):
def test_inject_dependency(signature_inspector):
"""Test inject_dependency."""
def sample_function( # type: ignore
async def sample_function( # type: ignore
cc: CommandContext,
provider_choices: ProviderChoices,
standard_params: StandardParams,
@@ -251,7 +251,7 @@ def test_inject_dependency(signature_inspector):
def test_get_description(signature_inspector):
"""Test get_description."""
def some_function():
async def some_function():
"""Mock function."""
assert signature_inspector.get_description(some_function) == some_function.__doc__
@@ -260,7 +260,7 @@ def test_get_description(signature_inspector):
def test_get_description_no_doc(signature_inspector):
"""Test get_description."""
def some_function():
async def some_function():
pass
assert not signature_inspector.get_description(some_function)

View File

@@ -120,10 +120,10 @@ def query_instance():
)
def test_execute_method_fake_credentials(query_instance, mock_registry):
async def test_execute_method_fake_credentials(query_instance: Query, mock_registry):
"""Test execute method without setting credentials."""
mock_fetch_result = MockBaseModel()
mock_registry.fetch.return_value = mock_fetch_result
with pytest.raises(Exception):
query_instance.execute()
await query_instance.execute()

View File

@@ -36,12 +36,12 @@ class MockFetcher(Fetcher[MockQueryParams, List[MockData]]):
return [MockData(**item) for item in data]
def test_fetcher_methods():
async def test_fetcher_methods():
"""Test the Fetcher abstract methods using a mock Fetcher subclass."""
params = {"param1": "value1"}
mock_fetcher = MockFetcher()
fetched_data = mock_fetcher.fetch_data(params=params)
fetched_data = await mock_fetcher.fetch_data(params=params)
assert isinstance(fetched_data, list)
assert isinstance(fetched_data[0], MockData)
assert fetched_data[0].model_dump() == {"mock_key": "mock_value"}

View File

@@ -91,15 +91,17 @@ def test_filter_credentials_missing_dont_require(mock_query_executor):
assert filtered_credentials == {}
def test_execute_success(mock_query_executor):
async def test_execute_success(mock_query_executor: QueryExecutor):
"""Test if the method can execute a query successfully."""
mock_result = {"data": "test_data"}
params = {"param1": "value1"}
credentials = {"api_key": SecretStr("12345")}
with patch.object(Fetcher, "fetch_data", return_value=mock_result) as mock_fetch:
result = mock_query_executor.execute(
async with patch.object(
Fetcher, "fetch_data", return_value=mock_result
) as mock_fetch:
result = await mock_query_executor.execute(
"test_provider", "test_fetcher", params, credentials
)