This commit is contained in:
Igor Radovanovic
2023-09-29 17:16:51 +02:00
parent 5c952b6af6
commit 7daf6ae4a0
3 changed files with 66 additions and 5 deletions

View File

@@ -25,7 +25,13 @@
- [Environment and dependencies](#environment-and-dependencies)
- [Python package](#python-package)
- [Overview](#overview)
- [QA your extension](#qa-your-extension)
- [Unit tests](#unit-tests)
- [Integration tests](#integration-tests)
- [Import time](#import-time)
- [Sharing your extension](#sharing-your-extension)
- [Publish your extension to PyPI](#publish-your-extension-to-pypi)
- [Create a PR to the OpenBB Platform](#create-a-pr-to-the-openbb-platform)
## Contributing Introduction
@@ -497,6 +503,54 @@ You can do that with:
python -c "import openbb; openbb.build()"
```
## QA your extension
We are strong believers in the QA process and we want to make sure that all the extensions that are added to the OpenBB Platform are of high quality. To ensure this, we have a set of QA tools that you can use to test your extension.
Primarily, we have tools that semi-automate the creation of unit and integration tests.
> The QA tools are still in development and we are constantly improving them.
### Unit tests
Each `Fetcher` comes equipped with a `test` method that will ensure that it is implemented correctly and that it is returning the expected data. It also ensures that all types are correct and that the data is valid.
To create unit tests for your Fetchers, you can run the following command:
```bash
python openbb_platform/providers/tests/utils/unit_test_generator.py
```
> Note that you should be running this file from the root of the repository.
The automatic unit test generation will add unit tests for all the fetchers available in a given provider.
> Note that sometimes manual intervention is needed. For example, adjusting out-of-top level imports or adding specific arguments for a given fetcher.
### Integration tests
The integration tests are a bit more complex than the unit tests, as we want to test both the Python interface and the API interface. For this, we have two scripts that will help you generate the integration tests.
To generate the integration tests for the Python interface, you can run the following command:
```bash
python openbb_platform/extensions/tests/utils/integration_tests_generator.py
```
To generate the integration tests for the API interface, you can run the following command:
```bash
python openbb_platform/extensions/tests/utils/integration_tests_api_generator.py
```
When testing the API interface, you'll need to run the OpenBB Platform locally before running the tests. To do so, you can run the following command:
```bash
uvicorn openbb_platform.platform.core.openbb_core.api.rest_api:app --host 0.0.0.0 --port 8000 --reload
```
These automated tests are a great way to reduce the amount of code you need to write, but they are not a replacement for manual testing and might require tweaking. That's why we have unit tests that test the generated integration tests to ensure they cover all providers and parameters.
### Import time
We aim to have a short import time for the package. To measure that we use `tuna`.
@@ -511,3 +565,9 @@ pip install tuna
python -X importtime openbb/__init__.py 2> import.log
tuna import.log
```
## Sharing your extension
### Publish your extension to PyPI
### Create a PR to the OpenBB Platform

View File

@@ -1,10 +1,10 @@
import os
from platform.core.openbb_core.app.provider_interface import ProviderInterface
from platform.core.openbb_core.app.router import CommandMap
from typing import Dict, List, Type, get_type_hints
import requests
from extensions.tests.utils.integration_tests_generator import get_test_params
from openbb_core.app.provider_interface import ProviderInterface
from openbb_core.app.router import CommandMap
def get_http_method(api_paths: Dict[str, dict], route: str):

View File

@@ -1,9 +1,9 @@
"""Integration test generator."""
from pathlib import Path, PosixPath
from platform.core.openbb_core.app.provider_interface import ProviderInterface
from platform.core.openbb_core.app.router import CommandMap
from typing import Any, Dict, List, Literal, get_origin
from openbb_core.app.provider_interface import ProviderInterface
from openbb_core.app.router import CommandMap
from pydantic.fields import FieldInfo
from pydantic_core import PydanticUndefined
@@ -181,4 +181,5 @@ def write_integration_test() -> None:
add_test_commands_to_file(extensions)
write_integration_test()
if __name__ == "__main__":
write_integration_test()