mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-06 09:22:26 +00:00
Tests pt1
This commit is contained in:
@@ -183,6 +183,7 @@ def format_data_to_plot(data: pd.DataFrame, detail: dict) -> Tuple[pd.DataFrame,
|
||||
|
||||
return data_to_plot, title
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
@check_api_key(["API_FRED_KEY"])
|
||||
def display_yield_curve(
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
futures display a futures and commodities overview [WallStreetJournal, Finviz]
|
||||
map S&P500 index stocks map [Finviz]
|
||||
bigmac The Economist Big Mac index [Nasdaq]
|
||||
ycrv show sovereign yield curves [FRED]
|
||||
events show economic calendar [Nasdaq]
|
||||
edebt show external debt statistics for various countries [Wikipedia]
|
||||
|
||||
|
||||
192
tests/openbb_terminal/fixedincome/test_fixedincome_controller.py
Normal file
192
tests/openbb_terminal/fixedincome/test_fixedincome_controller.py
Normal file
@@ -0,0 +1,192 @@
|
||||
import os
|
||||
import pytest
|
||||
|
||||
from openbb_terminal.fixedincome import fixedincome_controller
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], ["help"]),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
path_controller = "openbb_terminal.fixedincome.fixedincome_controller"
|
||||
|
||||
# MOCK SWITCH
|
||||
mocker.patch(
|
||||
target=f"{path_controller}.FixedIncomeController.switch",
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = fixedincome_controller.FixedIncomeController(queue=queue).menu()
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
path_controller = "openbb_terminal.fixedincome.fixedincome_controller"
|
||||
|
||||
# ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU
|
||||
mocker.patch(
|
||||
target="openbb_terminal.feature_flags.USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="openbb_terminal.parent_classes.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="openbb_terminal.parent_classes.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
# DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER
|
||||
mocker.patch.object(
|
||||
target=fixedincome_controller.obbff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target=f"{path_controller}.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target=f"{path_controller}.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = fixedincome_controller.FixedIncomeController(queue=None).menu()
|
||||
|
||||
assert result_menu == ["help"]
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
path_controller = "openbb_terminal.fixedincome.fixedincome_controller"
|
||||
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=fixedincome_controller.obbff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target=f"{path_controller}.session",
|
||||
return_value=None,
|
||||
)
|
||||
|
||||
# MOCK USER INPUT
|
||||
mocker.patch("builtins.input", return_value=mock_input)
|
||||
|
||||
# MOCK SWITCH
|
||||
class SystemExitSideEffect:
|
||||
def __init__(self):
|
||||
self.first_call = True
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch(
|
||||
target=f"{path_controller}.FixedIncomeController.switch",
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
result_menu = fixedincome_controller.FixedIncomeController(queue=None).menu()
|
||||
|
||||
assert result_menu == ["help"]
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
controller = fixedincome_controller.FixedIncomeController(queue=None)
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["home", "help"]),
|
||||
("help/help", ["help", "help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
(
|
||||
"r",
|
||||
[
|
||||
"quit",
|
||||
"reset",
|
||||
"fixedincome",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = fixedincome_controller.FixedIncomeController(queue=None)
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
|
||||
controller = fixedincome_controller.FixedIncomeController(queue=None)
|
||||
controller.call_cls([])
|
||||
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
["quit", "quit"],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "help"]),
|
||||
("call_home", [], ["quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"reset",
|
||||
"fixedincome",
|
||||
],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
[
|
||||
"quit",
|
||||
"reset",
|
||||
"fixedincome",
|
||||
"help",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, func, queue):
|
||||
controller = fixedincome_controller.FixedIncomeController(queue=queue)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
27
tests/openbb_terminal/fixedincome/txt/test_fixedincome_controller/test_print_help.txt
vendored
Normal file
27
tests/openbb_terminal/fixedincome/txt/test_fixedincome_controller/test_print_help.txt
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
Reference rates:
|
||||
estr euro short-term rate (estr) [FRED, ECB]
|
||||
sofr secured overnight financing rate (sofr) [FRED]
|
||||
sonia sterling overnight index average (sonia) [FRED]
|
||||
ameribor american interbank offered rate (ameribor) [FRED]
|
||||
|
||||
Central bank rates:
|
||||
fed effective federal funds rate [FRED]
|
||||
projection the Federal Reserve's projection of the federal funds rate. [FRED]
|
||||
iorb interest rate on reserve balances [FRED]
|
||||
dwpcr discount window primary credit rate [FRED]
|
||||
ecb key ECB interest rates [FRED]
|
||||
|
||||
Government Bonds:
|
||||
treasury plot countries (including forecast) treasury rates [OECD]
|
||||
usrates plot secondary market, constant maturity or inflation protected rates [FRED]
|
||||
ycrv plot US yield curve [FRED]
|
||||
ecbycrv plot euro area yield curve [ECB]
|
||||
|
||||
Corporate Bonds:
|
||||
|
||||
Spreads:
|
||||
|
||||
tmc 10-year treasury constant maturity minus selected treasury constant maturity [FRED]
|
||||
ffrmc selected treasury constant maturity minus federal funds rate [FRED]
|
||||
tbffr selected treasury bill minus federal funds rate [FRED]
|
||||
|
||||
Reference in New Issue
Block a user