Update tests

This commit is contained in:
Theodore Aptekarev
2023-09-01 16:45:06 +02:00
parent 86b77960db
commit 6fb25f0a93
2 changed files with 77 additions and 11 deletions

View File

@@ -116,9 +116,61 @@ def test_to_dataframe_no_results():
{"0": [0, 2], "1": [1, 3], "2": [2, 0], "3": [3, 1], "4": [4, 6]}
),
),
# Test case 9: Empty results
# Test case 9: List of dict of data
(
[
{
"df1": [
Data(date="1956-01-01", another_date="2023-09-01", value=0.0),
Data(date="1956-02-01", another_date="2023-09-01", value=0.0),
Data(date="1956-03-01", another_date="2023-09-01", value=0.0),
],
"df2": [
Data(date="1955-03-01", another_date="2023-09-01", value=0.0),
Data(date="1955-04-01", another_date="2023-09-01", value=0.0),
Data(date="1955-05-01", another_date="2023-09-01", value=0.0),
],
}
],
pd.concat(
{
"df1": pd.DataFrame(
{
"date": [
pd.to_datetime("1956-01-01"),
pd.to_datetime("1956-02-01"),
pd.to_datetime("1956-03-01"),
],
"another_date": [
"2023-09-01",
"2023-09-01",
"2023-09-01",
],
"value": [0.0, 0.0, 0.0],
}
).set_index("date"),
"df2": pd.DataFrame(
{
"date": [
pd.to_datetime("1955-03-01"),
pd.to_datetime("1955-04-01"),
pd.to_datetime("1955-05-01"),
],
"another_date": [
"2023-09-01",
"2023-09-01",
"2023-09-01",
],
"value": [0.0, 0.0, 0.0],
}
).set_index("date"),
},
axis=1,
),
),
# Test case 10: Empty results
([], OpenBBError("Results not found.")),
# Test case 10: Results as None, should raise OpenBBError
# Test case 11: Results as None, should raise OpenBBError
(None, OpenBBError("Results not found.")),
],
)

View File

@@ -1,3 +1,4 @@
"""Test charting manager."""
import pytest
from openbb_core.app.charting_manager import ChartingManager
from openbb_core.app.model.system_settings import SystemSettings
@@ -6,34 +7,39 @@ from openbb_core.app.model.user_settings import UserSettings
@pytest.fixture(scope="function", autouse=True)
def setup_and_teardown():
"""Prepare test context."""
# Code to run before each test function
yield # This is where the test function runs
# Code to run after each test function
ChartingManager._instances = {}
ChartingManager._instances = {} # pylint: disable=protected-access
def test_charting_manager():
assert ChartingManager()
"""Smoke test."""
assert ChartingManager() is not None # noqa: S101
def test_charting_manager_singleton_prop():
"""Smoke test."""
cm_1 = ChartingManager()
cm_2 = ChartingManager()
assert cm_1 is cm_2
assert cm_1 is cm_2 # noqa: S101
def test_charting_settings():
"""Test helper."""
sys = SystemSettings(test_mode=True)
user = UserSettings(preferences={"plot_enable_pywry": False})
cm = ChartingManager(user_settings=user, system_settings=sys)
assert cm.charting_settings.plot_enable_pywry is False
assert cm.charting_settings.test_mode is True
assert cm.charting_settings.plot_enable_pywry is False # noqa: S101
assert cm.charting_settings.test_mode is True # noqa: S101
def test_charting_settings_setter():
"""Test helper."""
cm = ChartingManager()
sys = SystemSettings(test_mode=True)
@@ -41,12 +47,20 @@ def test_charting_settings_setter():
cm.charting_settings = (sys, user)
assert cm.charting_settings.plot_enable_pywry is False
assert cm.charting_settings.test_mode is True
assert cm.charting_settings.plot_enable_pywry is False # noqa: S101
assert cm.charting_settings.test_mode is True # noqa: S101
def test_check_charting_extension_installed():
"""Test helper."""
cm = ChartingManager()
assert cm.check_charting_extension_installed("openbb_charting") is True
assert cm.check_charting_extension_installed("openbb_core_extension_2") is False
try:
import openbb_charting # pylint: disable=unused-import,import-outside-toplevel # noqa: F401,E501
assert cm.check_charting_extension_installed("charting") is True # noqa: S101
except ImportError:
assert cm.check_charting_extension_installed("charting") is False # noqa: S101
assert ( # noqa: S101
cm.check_charting_extension_installed("openbb_core_extension_2") is False
)