mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 05:52:23 +00:00
* bump * Update ALL the exports with sheet name option * Update contributing too * Add in sheet name to each docstring * Update tests * Fix the small things for tests * Converting CONTRIBUTING.md back since I put minimal changes in and it complains * Fix terminal exit after `--sort p/e` (#4013) * fix scr sort exit * rewrite unit test output * rewind slash replace * rewind slash replace * fix regex * rewrite expected scr tests * black Co-authored-by: James Maslek <jmaslek11@gmail.com> * fix: small typo (#4036) * fix income comparison error (#4029) * Update tests due to yfinance error * I broke tests and fixed them * Fix tests? * Missed a few sheet name additions * missed one more * Fix some missing sheet_name parameters * Fix a test I broke * Update tests due to changes with sheet_name * Update stocks and common * Mutual funds just because * Portfolio update * Update Forecast * Update Futures * Update ETF * Update Economy * Update Crypto * Update others * Update documentation to explain --sheet-name * It should be None test * Add None for sheet_name since empty string can result in errors * Formatting * Fix tests * Update documentation * Also update the image * Add back to options commands Co-authored-by: james <jmaslek11@gmail.com> Co-authored-by: Jeroen Bouma <jeroenbouma@Jeroens-MacBook-Pro.local> Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com> Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com> Co-authored-by: teh_coderer <me@tehcoderer.com>
108 lines
3.0 KiB
Python
108 lines
3.0 KiB
Python
from datetime import datetime, timedelta
|
|
from unittest.mock import MagicMock
|
|
import pytest
|
|
import pandas as pd
|
|
|
|
from openbb_terminal.common.quantitative_analysis import qa_view
|
|
|
|
dates = [datetime.now() - timedelta(days=x) for x in range(10)]
|
|
nums = list(range(1, 11))
|
|
data = {"date": dates, "col2": nums, "col1": [x - timedelta(days=1) for x in dates]}
|
|
data2 = {"date": nums, "col2": nums, "col1": dates}
|
|
df = pd.DataFrame(data).set_index("date")
|
|
df2 = pd.DataFrame(data2).set_index("date")
|
|
series = pd.Series(dict(zip(dates, nums)), name="Series")
|
|
|
|
# pylint: disable=unsupported-assignment-operation
|
|
|
|
|
|
@pytest.mark.parametrize("val", [0.04, 1])
|
|
def test_lambda_color_red(val):
|
|
qa_view.lambda_color_red(val)
|
|
|
|
|
|
def test_display_summary():
|
|
qa_view.display_summary(pd.DataFrame(data, columns=["col1", "col2"]), "xlsx", None)
|
|
|
|
|
|
@pytest.mark.parametrize("df_use, external", [(df, None), (df2, None), (df, [1, 2])])
|
|
def test_display_hist(df_use, external):
|
|
qa_view.display_hist(df_use, "col2", "Data", 2, external)
|
|
|
|
|
|
def test_display_hist_fail():
|
|
with pytest.raises(Exception):
|
|
qa_view.display_hist(df, "col1", "Data", 2, [MagicMock()])
|
|
|
|
|
|
@pytest.mark.parametrize("external", [None, [1, 2]])
|
|
def test_display_cdf(external):
|
|
qa_view.display_cdf(df, "col2", "Data", "xlsx", None, external)
|
|
|
|
|
|
def test_display_cdf_fail():
|
|
with pytest.raises(Exception):
|
|
qa_view.display_cdf(df, "col1", "Data", 2, [MagicMock()])
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"external, yearly", [(None, False), (None, True), ([1, 2], False)]
|
|
)
|
|
def test_display_bw(external, yearly):
|
|
qa_view.display_bw(df, "col2", "Data", yearly, external)
|
|
|
|
|
|
@pytest.mark.parametrize("external, yearly", [([1, 2], False)])
|
|
def test_display_acf(external, yearly):
|
|
qa_view.display_acf(df2, "col2", "Data", yearly, external)
|
|
|
|
|
|
@pytest.mark.parametrize("external", [None, [1, 2]])
|
|
def test_display_qqplot(external):
|
|
qa_view.display_qqplot(df, "col2", "Data", external)
|
|
|
|
|
|
def test_display_cusum():
|
|
qa_view.display_cusum(df, "col2", 1, 1, None)
|
|
|
|
|
|
def test_display_cusum_fail():
|
|
with pytest.raises(Exception):
|
|
qa_view.display_cusum(df, "col2", 1, 1, [1, 2])
|
|
|
|
|
|
@pytest.mark.parametrize("yearly", [False, True])
|
|
def test_display_seasonal(yearly):
|
|
qa_view.display_seasonal("Data", df, "col2", yearly, "xlsx", None)
|
|
|
|
|
|
def test_display_normality():
|
|
qa_view.display_normality(df, "col2", "xlsx", None)
|
|
|
|
|
|
def test_display_unitroot():
|
|
qa_view.display_unitroot(df, "col2", "c", "c")
|
|
|
|
|
|
@pytest.mark.parametrize("use_df", [df, series])
|
|
def test_display_raw(use_df):
|
|
sort = "col1" if isinstance(use_df, pd.DataFrame) else ""
|
|
qa_view.display_raw(use_df, sort)
|
|
|
|
|
|
@pytest.mark.parametrize("y, external", [(True, None), (False, None), (True, [1, 2])])
|
|
def test_display_line(y, external):
|
|
qa_view.display_line(
|
|
series,
|
|
log_y=y,
|
|
markers_lines=True,
|
|
markers_scatter=dates,
|
|
external_axes=external,
|
|
title=True,
|
|
)
|
|
|
|
|
|
def test_display_var():
|
|
df["adjclose"] = df["col2"]
|
|
qa_view.display_var(df, "TSLA", True, True, 50, True)
|