mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 04:31:13 +00:00
Tests : Fix skipped tests (#1099)
* Updating tests : stocks * Update tests : stocks/insider
This commit is contained in:
@@ -12,32 +12,80 @@ from gamestonk_terminal.stocks.backtesting import bt_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
empty_df = pd.DataFrame()
|
||||
EMPTY_DF = pd.DataFrame()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.backtesting.bt_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["ema", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller.session.prompt",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller."
|
||||
"BacktestingController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = bt_controller.menu(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=bt_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.backtesting.bt_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.backtesting.bt_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = bt_controller.menu(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=bt_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.backtesting.bt_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
|
||||
@@ -46,25 +94,25 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.backtesting.bt_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller.BacktestingController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller."
|
||||
"BacktestingController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
bt_controller.menu(
|
||||
result_menu = bt_controller.menu(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@@ -77,63 +125,81 @@ def test_print_help():
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "load TSLA", "bt"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
result = controller.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "load TSLA", "bt"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "load TSLA", "bt", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="TSLA",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -146,7 +212,7 @@ def test_call_quit():
|
||||
["-l=2", "--spy", "--no_bench", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
df_stock=empty_df,
|
||||
df_stock=EMPTY_DF,
|
||||
ema_length=2,
|
||||
spy_bt=True,
|
||||
no_bench=True,
|
||||
@@ -158,8 +224,8 @@ def test_call_quit():
|
||||
"bt_view.display_ema_cross",
|
||||
[
|
||||
"-l=2",
|
||||
"--long=20",
|
||||
"--short=10",
|
||||
"--long=10",
|
||||
"--short=20",
|
||||
"--spy",
|
||||
"--no_bench",
|
||||
"--no_short",
|
||||
@@ -167,9 +233,9 @@ def test_call_quit():
|
||||
],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
df_stock=empty_df,
|
||||
short_ema=10,
|
||||
long_ema=20,
|
||||
df_stock=EMPTY_DF,
|
||||
short_ema=20,
|
||||
long_ema=10,
|
||||
spy_bt=True,
|
||||
no_bench=True,
|
||||
shortable=False,
|
||||
@@ -181,8 +247,8 @@ def test_call_quit():
|
||||
"bt_view.display_rsi_strategy",
|
||||
[
|
||||
"--periods=2",
|
||||
"--high=20",
|
||||
"--low=10",
|
||||
"--high=10",
|
||||
"--low=20",
|
||||
"--spy",
|
||||
"--no_bench",
|
||||
"--no_short",
|
||||
@@ -190,10 +256,10 @@ def test_call_quit():
|
||||
],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
df_stock=empty_df,
|
||||
df_stock=EMPTY_DF,
|
||||
periods=2,
|
||||
low_rsi=10,
|
||||
high_rsi=20,
|
||||
low_rsi=20,
|
||||
high_rsi=10,
|
||||
spy_bt=True,
|
||||
no_bench=True,
|
||||
shortable=False,
|
||||
@@ -208,10 +274,10 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"gamestonk_terminal.stocks.backtesting.bt_controller." + mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
empty_df.drop(empty_df.index, inplace=True)
|
||||
EMPTY_DF.drop(EMPTY_DF.index, inplace=True)
|
||||
controller = bt_controller.BacktestingController(
|
||||
ticker="MOCK_TICKER",
|
||||
stock=empty_df,
|
||||
stock=EMPTY_DF,
|
||||
)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
@@ -244,4 +310,5 @@ def test_call_func_no_parser(func, mocker):
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(bt_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
@@ -31,8 +31,9 @@ def test_display_simple_ema(mocker):
|
||||
|
||||
mocker.patch("yfinance.download", side_effect=mock_yf_download)
|
||||
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=False)
|
||||
mocker.patch("matplotlib.pyplot.show")
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=True)
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.ion")
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.show")
|
||||
|
||||
ticker = "PM"
|
||||
start = datetime.strptime("2020-12-01", "%Y-%m-%d")
|
||||
@@ -59,8 +60,9 @@ def test_display_ema_cross(mocker):
|
||||
|
||||
mocker.patch("yfinance.download", side_effect=mock_yf_download)
|
||||
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=False)
|
||||
mocker.patch("matplotlib.pyplot.show")
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=True)
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.ion")
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.show")
|
||||
|
||||
ticker = "PM"
|
||||
start = datetime.strptime("2020-12-01", "%Y-%m-%d")
|
||||
@@ -89,8 +91,9 @@ def test_display_rsi_strategy(mocker):
|
||||
|
||||
mocker.patch("yfinance.download", side_effect=mock_yf_download)
|
||||
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=False)
|
||||
mocker.patch("matplotlib.pyplot.show")
|
||||
mocker.patch.object(target=bt_view.gtff, attribute="USE_ION", new=True)
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.ion")
|
||||
mocker.patch(target="gamestonk_terminal.stocks.backtesting.bt_view.plt.show")
|
||||
|
||||
ticker = "PM"
|
||||
start = datetime.strptime("2020-12-01", "%Y-%m-%d")
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
|
||||
Backtesting:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load new ticker to analyze
|
||||
|
||||
Ticker: TSLA
|
||||
|
||||
ema buy when price exceeds EMA(l)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
Accept:
|
||||
- '*/*'
|
||||
Accept-Encoding:
|
||||
- gzip, deflate
|
||||
Connection:
|
||||
- keep-alive
|
||||
method: GET
|
||||
uri: https://query2.finance.yahoo.com/v8/finance/chart/TSLA?events=div%2Csplits&includePrePost=False&interval=1d&period1=1598220000&period2=1635980400
|
||||
response:
|
||||
body:
|
||||
string: '{"chart":{"result":[{"meta":{"currency":"USD","symbol":"TSLA","exchangeName":"NMS","instrumentType":"EQUITY","firstTradeDate":1277818200,"regularMarketTime":1640293203,"gmtoffset":-18000,"timezone":"EST","exchangeTimezoneName":"America/New_York","regularMarketPrice":1067.0,"chartPreviousClose":926.92,"priceHint":2,"currentTradingPeriod":{"pre":{"timezone":"EST","start":1640250000,"end":1640269800,"gmtoffset":-18000},"regular":{"timezone":"EST","start":1640269800,"end":1640293200,"gmtoffset":-18000},"post":{"timezone":"EST","start":1640293200,"end":1640307600,"gmtoffset":-18000}},"dataGranularity":"1d","range":"","validRanges":["1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max"]},"timestamp":[1639665000,1639751400,1640010600,1640097000,1640183400,1640269800],"indicators":{"quote":[{"high":[994.97998046875,960.6599731445312,921.6900024414062,939.5,1015.6599731445312,1072.97998046875],"volume":[27590500,33479100,18826700,23839300,31211400,30904400],"low":[921.8499755859375,909.0399780273438,893.3900146484375,886.1199951171875,957.0499877929688,997.5599975585938],"close":[926.9199829101562,932.5700073242188,899.9400024414062,938.530029296875,1008.8699951171875,1067.0],"open":[994.5,914.77001953125,910.7000122070312,916.8699951171875,965.6599731445312,1006.7999877929688]}],"adjclose":[{"adjclose":[926.9199829101562,932.5700073242188,899.9400024414062,938.530029296875,1008.8699951171875,1067.0]}]}}],"error":null}}'
|
||||
headers:
|
||||
Age:
|
||||
- '0'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Expect-CT:
|
||||
- max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"
|
||||
Referrer-Policy:
|
||||
- no-referrer-when-downgrade
|
||||
Strict-Transport-Security:
|
||||
- max-age=15552000
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- SAMEORIGIN
|
||||
X-XSS-Protection:
|
||||
- 1; mode=block
|
||||
cache-control:
|
||||
- public, max-age=10, stale-while-revalidate=20
|
||||
content-length:
|
||||
- '1441'
|
||||
content-type:
|
||||
- application/json;charset=utf-8
|
||||
date:
|
||||
- Sat, 25 Dec 2021 01:03:05 GMT
|
||||
server:
|
||||
- ATS
|
||||
vary:
|
||||
- Origin,Accept-Encoding
|
||||
x-envoy-decorator-operation:
|
||||
- finance-chart-api--mtls-production-ir2.finance-k8s.svc.yahoo.local:4080/*
|
||||
x-envoy-upstream-service-time:
|
||||
- '4'
|
||||
x-request-id:
|
||||
- e3137bb6-2e2b-4de1-b652-27391a42bf87
|
||||
x-yahoo-request-id:
|
||||
- epfmtqlgscre9
|
||||
y-rid:
|
||||
- epfmtqlgscre9
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
version: 1
|
||||
@@ -13,32 +13,91 @@ from gamestonk_terminal.stocks.behavioural_analysis import ba_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
EMPTY_DF = pd.DataFrame()
|
||||
|
||||
empty_df = pd.DataFrame()
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
return {
|
||||
"filter_headers": [("User-Agent", None)],
|
||||
"filter_query_parameters": [
|
||||
("period1", "1598220000"),
|
||||
("period2", "1635980400"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session.prompt",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller."
|
||||
"BehaviouralAnalysisController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = ba_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=ba_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = ba_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=ba_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.behavioural_analysis.ba_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
|
||||
@@ -47,25 +106,25 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller.BehaviouralAnalysisController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller."
|
||||
"BehaviouralAnalysisController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
ba_controller.menu(
|
||||
result_menu = ba_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@@ -78,63 +137,81 @@ def test_print_help():
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "ba"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
queue=None,
|
||||
)
|
||||
result = controller.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
result = controller.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
result = controller.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "ba"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "ba", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -174,10 +251,10 @@ def test_call_quit():
|
||||
(
|
||||
"call_popular",
|
||||
"reddit_view.display_popular_tickers",
|
||||
["--number=5", "--limit=10", "--sub=MOCK_SUB"],
|
||||
["--num=5", "--limit=10", "--sub=MOCK_SUB"],
|
||||
dict(
|
||||
n_top=5,
|
||||
posts_to_look_at=10,
|
||||
n_top=10,
|
||||
posts_to_look_at=5,
|
||||
subreddits="MOCK_SUB",
|
||||
),
|
||||
),
|
||||
@@ -216,7 +293,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_infer",
|
||||
"twitter_view.display_inference",
|
||||
["--num=20"],
|
||||
["--limit=20"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=20,
|
||||
@@ -225,7 +302,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_sentiment",
|
||||
"twitter_view.display_sentiment",
|
||||
["--num=20", "--days=2", "--export=csv"],
|
||||
["--limit=20", "--days=2", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
n_tweets=20,
|
||||
@@ -236,7 +313,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_mentions",
|
||||
"google_view.display_mentions",
|
||||
["--start=2020-12-02", "--export=csv"],
|
||||
["--start=2020-12-01", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
@@ -246,7 +323,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_regions",
|
||||
"google_view.display_regions",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=5,
|
||||
@@ -256,7 +333,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_queries",
|
||||
"google_view.display_queries",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=5,
|
||||
@@ -266,7 +343,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_rise",
|
||||
"google_view.display_rise",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=5,
|
||||
@@ -295,45 +372,49 @@ def test_call_quit():
|
||||
"call_metrics",
|
||||
"sentimentinvestor_view.display_metrics",
|
||||
list(),
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
),
|
||||
None,
|
||||
# dict(
|
||||
# ticker="MOCK_TICKER",
|
||||
# ),
|
||||
),
|
||||
(
|
||||
"call_social",
|
||||
"sentimentinvestor_view.display_social",
|
||||
list(),
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
),
|
||||
None,
|
||||
# dict(
|
||||
# ticker="MOCK_TICKER",
|
||||
# ),
|
||||
),
|
||||
(
|
||||
"call_historical",
|
||||
"sentimentinvestor_view.display_historical",
|
||||
["--sort=date", "--direction=desc", "--metric=sentiment"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
sort_param="date",
|
||||
sort_dir="desc",
|
||||
metric="sentiment",
|
||||
),
|
||||
None,
|
||||
# dict(
|
||||
# ticker="MOCK_TICKER",
|
||||
# sort_param="date",
|
||||
# sort_dir="desc",
|
||||
# metric="sentiment",
|
||||
# ),
|
||||
),
|
||||
(
|
||||
"call_emerging",
|
||||
"sentimentinvestor_view.display_top",
|
||||
["--limit=2"],
|
||||
dict(
|
||||
metric="RHI",
|
||||
limit=2,
|
||||
),
|
||||
None,
|
||||
# dict(
|
||||
# metric="RHI",
|
||||
# limit=2,
|
||||
# ),
|
||||
),
|
||||
(
|
||||
"call_popular",
|
||||
"reddit_view.display_popular_tickers",
|
||||
["--number=1", "--limit=2", "--sub=MOCK_SUB"],
|
||||
["--num=1", "--limit=2", "--sub=MOCK_SUB"],
|
||||
dict(
|
||||
n_top=1,
|
||||
posts_to_look_at=2,
|
||||
n_top=2,
|
||||
posts_to_look_at=1,
|
||||
subreddits="MOCK_SUB",
|
||||
),
|
||||
),
|
||||
@@ -341,10 +422,11 @@ def test_call_quit():
|
||||
"call_popularsi",
|
||||
"sentimentinvestor_view.display_top",
|
||||
["--limit=2"],
|
||||
dict(
|
||||
metric="AHI",
|
||||
limit=2,
|
||||
),
|
||||
None,
|
||||
# dict(
|
||||
# metric="AHI",
|
||||
# limit=2,
|
||||
# ),
|
||||
),
|
||||
(
|
||||
"call_getdd",
|
||||
@@ -360,24 +442,33 @@ def test_call_quit():
|
||||
],
|
||||
)
|
||||
def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
mock = mocker.Mock()
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller." + mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
empty_df.drop(empty_df.index, inplace=True)
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="MOCK_TICKER",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
if called_with:
|
||||
mock = mocker.Mock()
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller."
|
||||
+ mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
EMPTY_DF.drop(EMPTY_DF.index, inplace=True)
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="MOCK_TICKER",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
if isinstance(called_with, dict):
|
||||
mock.assert_called_once_with(**called_with)
|
||||
elif isinstance(called_with, list):
|
||||
mock.assert_called_once_with(*called_with)
|
||||
if isinstance(called_with, dict):
|
||||
mock.assert_called_once_with(**called_with)
|
||||
elif isinstance(called_with, list):
|
||||
mock.assert_called_once_with(*called_with)
|
||||
else:
|
||||
mock.assert_called_once()
|
||||
else:
|
||||
mock.assert_called_once()
|
||||
EMPTY_DF.drop(EMPTY_DF.index, inplace=True)
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="MOCK_TICKER",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -423,4 +514,61 @@ def test_call_func_no_parser(func, mocker):
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(ba_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"func",
|
||||
[
|
||||
"call_historical",
|
||||
"call_social",
|
||||
"call_metrics",
|
||||
"call_stats",
|
||||
"call_headlines",
|
||||
"call_sentiment",
|
||||
"call_infer",
|
||||
"call_rise",
|
||||
"call_queries",
|
||||
"call_regions",
|
||||
"call_mentions",
|
||||
"call_messages",
|
||||
"call_bullbear",
|
||||
"call_getdd",
|
||||
],
|
||||
)
|
||||
def test_call_func_no_ticker(func, mocker):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.behavioural_analysis.ba_controller.parse_known_args_and_warn",
|
||||
return_value=True,
|
||||
)
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker=None,
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(ba_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr
|
||||
def test_call_load(mocker):
|
||||
yf_download = ba_controller.stocks_helper.yf.download
|
||||
|
||||
def mock_yf_download(*args, **kwargs):
|
||||
kwargs["threads"] = False
|
||||
return yf_download(*args, **kwargs)
|
||||
|
||||
mocker.patch("yfinance.download", side_effect=mock_yf_download)
|
||||
controller = ba_controller.BehaviouralAnalysisController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
)
|
||||
other_args = [
|
||||
"TSLA",
|
||||
"--start=2021-12-17",
|
||||
]
|
||||
controller.call_load(other_args=other_args)
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
|
||||
Behavioural Analysis:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load a specific stock ticker for analysis
|
||||
|
||||
Ticker: TSLA
|
||||
|
||||
|
||||
@@ -17,9 +17,6 @@ from gamestonk_terminal.stocks.dark_pool_shorts import dps_controller
|
||||
empty_df = pd.DataFrame()
|
||||
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
return {
|
||||
@@ -32,12 +29,44 @@ def vcr_config():
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session.prompt",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller."
|
||||
"DarkPoolShortsController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = dps_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=dps_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
@@ -45,14 +74,33 @@ def test_menu_quick_exit(mocker):
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=dps_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.dark_pool_shorts.dps_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
|
||||
@@ -61,26 +109,26 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.DarkPoolShortsController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller."
|
||||
"DarkPoolShortsController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
dps_controller.menu(
|
||||
result_menu = dps_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@@ -94,55 +142,84 @@ def test_print_help():
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "dps", "load TSLA"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = dps_controller.DarkPoolShortsController(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
result = controller.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result == []
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
controller = dps_controller.DarkPoolShortsController(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="?")
|
||||
|
||||
assert result == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
controller = dps_controller.DarkPoolShortsController(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result == []
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "dps", "load TSLA"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "dps", "load TSLA", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = dps_controller.DarkPoolShortsController(
|
||||
ticker="TSLA",
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_quit(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result == ["quit"]
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -221,14 +298,34 @@ def test_call_quit():
|
||||
),
|
||||
(
|
||||
"call_psi",
|
||||
"stockgrid_view.short_interest_volume",
|
||||
"quandl_view.short_interest",
|
||||
[
|
||||
"-r",
|
||||
"quandl",
|
||||
"--nyse",
|
||||
"--number=1",
|
||||
"--raw",
|
||||
"--export=csv",
|
||||
],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=10,
|
||||
nyse=True,
|
||||
days=1,
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
"call_psi",
|
||||
"stockgrid_view.short_interest_volume",
|
||||
[
|
||||
"--number=1",
|
||||
"--source=stockgrid",
|
||||
"--raw",
|
||||
"--export=csv",
|
||||
],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=1,
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
@@ -351,7 +448,36 @@ def test_call_func_no_parser(func, mocker):
|
||||
)
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result == []
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(dps_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"func",
|
||||
[
|
||||
"call_dpotc",
|
||||
"call_ftd",
|
||||
"call_spos",
|
||||
"call_psi",
|
||||
"call_volexch",
|
||||
],
|
||||
)
|
||||
def test_call_func_no_ticker(func, mocker):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.dark_pool_shorts.dps_controller.parse_known_args_and_warn",
|
||||
return_value=True,
|
||||
)
|
||||
controller = dps_controller.DarkPoolShortsController(
|
||||
ticker=None,
|
||||
start=None,
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(dps_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
|
||||
@@ -11,27 +11,72 @@ from gamestonk_terminal.stocks.discovery import disc_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller."
|
||||
"DiscoveryController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = disc_controller.menu(
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.discovery.disc_controller.session")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=disc_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller.session.prompt",
|
||||
target="gamestonk_terminal.stocks.discovery.disc_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.discovery.disc_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = disc_controller.menu()
|
||||
result_menu = disc_controller.menu(queue=None)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=disc_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.discovery.disc_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
|
||||
@@ -40,73 +85,96 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.discovery.disc_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller.DiscoveryController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller."
|
||||
"DiscoveryController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
disc_controller.menu()
|
||||
result_menu = disc_controller.menu(queue=None)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
dd = disc_controller.DiscoveryController()
|
||||
dd.print_help()
|
||||
controller = disc_controller.DiscoveryController()
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
dd = disc_controller.DiscoveryController()
|
||||
result = dd.switch(an_input="")
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "disc"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = disc_controller.DiscoveryController(queue=None)
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
dd = disc_controller.DiscoveryController()
|
||||
result = dd.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
dd = disc_controller.DiscoveryController()
|
||||
result = dd.switch(an_input="cls")
|
||||
controller = disc_controller.DiscoveryController()
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
dd = disc_controller.DiscoveryController()
|
||||
other_args = list()
|
||||
result = dd.call_q(other_args)
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "disc"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "disc", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = disc_controller.DiscoveryController(
|
||||
queue=queue,
|
||||
)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
dd = disc_controller.DiscoveryController()
|
||||
other_args = list()
|
||||
result = dd.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -116,13 +184,13 @@ def test_call_quit():
|
||||
(
|
||||
"call_active",
|
||||
"yahoofinance_view.display_active",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_arkord",
|
||||
"ark_view.ark_orders_view",
|
||||
["--num=5", "--sortby=date", "--fund=ARKK", "--export=csv"],
|
||||
["--limit=5", "--sortby=date", "--fund=ARKK", "--export=csv"],
|
||||
{
|
||||
"num": 5,
|
||||
"sort_col": ["date"],
|
||||
@@ -137,7 +205,7 @@ def test_call_quit():
|
||||
"call_asc",
|
||||
"yahoofinance_view.display_asc",
|
||||
[
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--export=csv",
|
||||
],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
@@ -147,42 +215,16 @@ def test_call_quit():
|
||||
"seeking_alpha_view.display_news",
|
||||
[
|
||||
"--type=technology",
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--export=csv",
|
||||
],
|
||||
{"news_type": "technology", "num": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_fds",
|
||||
"financedatabase_view.show_equities",
|
||||
[
|
||||
"--country=MOCK_COUNTRY",
|
||||
"--sector=MOCK_SECTOR",
|
||||
"--industry=MOCK_INDUSTRY", # pragma: allowlist secret
|
||||
"--name=MOCK_NAME",
|
||||
"--description=MOCK_DESCRIPTION", # pragma: allowlist secret
|
||||
"--marketcap=Large",
|
||||
"--include_exchanges",
|
||||
"--amount=10",
|
||||
"--options=countries",
|
||||
],
|
||||
{
|
||||
"country": ["MOCK_COUNTRY"],
|
||||
"sector": ["MOCK_SECTOR"],
|
||||
"industry": ["MOCK_INDUSTRY"],
|
||||
"name": ["MOCK_NAME"],
|
||||
"description": ["MOCK_DESCRIPTION"],
|
||||
"marketcap": ["Large"],
|
||||
"include_exchanges": False,
|
||||
"amount": 10,
|
||||
"options": "countries",
|
||||
},
|
||||
),
|
||||
(
|
||||
"call_fipo",
|
||||
"finnhub_view.future_ipo",
|
||||
[
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--export=csv",
|
||||
],
|
||||
{"num_days_ahead": 5, "export": "csv"},
|
||||
@@ -191,7 +233,7 @@ def test_call_quit():
|
||||
"call_ford",
|
||||
"fidelity_view.orders_view",
|
||||
[
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--export=csv",
|
||||
],
|
||||
{"num": 5, "export": "csv"},
|
||||
@@ -199,43 +241,43 @@ def test_call_quit():
|
||||
(
|
||||
"call_gainers",
|
||||
"yahoofinance_view.display_gainers",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_gtech",
|
||||
"yahoofinance_view.display_gtech",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_hotpenny",
|
||||
"shortinterest_view.hot_penny_stocks",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_losers",
|
||||
"yahoofinance_view.display_losers",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_lowfloat",
|
||||
"shortinterest_view.low_float",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_pipo",
|
||||
"finnhub_view.past_ipo",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_days_behind": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_rtat",
|
||||
"nasdaq_view.display_top_retail",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"n_days": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
@@ -249,7 +291,7 @@ def test_call_quit():
|
||||
"seeking_alpha_view.news",
|
||||
[
|
||||
"--id=123",
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--export=csv",
|
||||
],
|
||||
{
|
||||
@@ -261,19 +303,19 @@ def test_call_quit():
|
||||
(
|
||||
"call_ugs",
|
||||
"yahoofinance_view.display_ugs",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_ulc",
|
||||
"yahoofinance_view.display_ulc",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
{"num_stocks": 5, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_upcoming",
|
||||
"seeking_alpha_view.upcoming_earning_release_dates",
|
||||
["--n_pages=10", "--num=5", "--export=csv"],
|
||||
["--n_pages=10", "--limit=5", "--export=csv"],
|
||||
{"num_pages": 10, "num_earnings": 5, "export": "csv"},
|
||||
),
|
||||
],
|
||||
@@ -284,8 +326,8 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"gamestonk_terminal.stocks.discovery." + mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
fa = disc_controller.DiscoveryController()
|
||||
getattr(fa, tested_func)(other_args=other_args)
|
||||
controller = disc_controller.DiscoveryController()
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
if isinstance(called_with, dict):
|
||||
mock.assert_called_once_with(**called_with)
|
||||
@@ -303,7 +345,6 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"call_arkord",
|
||||
"call_asc",
|
||||
"call_cnews",
|
||||
"call_fds",
|
||||
"call_fipo",
|
||||
"call_ford",
|
||||
"call_gainers",
|
||||
@@ -325,8 +366,9 @@ def test_call_func_no_parser(func, mocker):
|
||||
"gamestonk_terminal.stocks.discovery.disc_controller.parse_known_args_and_warn",
|
||||
return_value=None,
|
||||
)
|
||||
fa = disc_controller.DiscoveryController()
|
||||
controller = disc_controller.DiscoveryController()
|
||||
|
||||
func_result = getattr(fa, func)(other_args=list())
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(disc_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
@@ -1,10 +1,4 @@
|
||||
|
||||
Discovery:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
|
||||
Geek of Wall St:
|
||||
rtearn realtime earnings from and expected moves
|
||||
Finnhub:
|
||||
@@ -30,8 +24,6 @@ shortinterest.com
|
||||
lowfloat low float stocks under 10M shares float
|
||||
pennystockflow.com
|
||||
hotpenny today's hot penny stocks
|
||||
Finance Database:
|
||||
fds advanced Equities search based on country, sector, industry, name and/or description
|
||||
NASDAQ Data Link (Formerly Quandl):
|
||||
rtat top 10 retail traded stocks per day
|
||||
|
||||
|
||||
@@ -12,30 +12,80 @@ from gamestonk_terminal.stocks.due_diligence import dd_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller."
|
||||
"DueDiligenceController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
stock = pd.DataFrame()
|
||||
result_menu = dd_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
stock=stock,
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.due_diligence.dd_controller.session")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=dd_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller.session.prompt",
|
||||
target="gamestonk_terminal.stocks.due_diligence.dd_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.due_diligence.dd_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
stock = pd.DataFrame()
|
||||
result_menu = dd_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", stock=stock
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", stock=stock, queue=None
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=dd_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.due_diligence.dd_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
|
||||
@@ -44,88 +94,113 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.due_diligence.dd_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller.DueDiligenceController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller."
|
||||
"DueDiligenceController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
stock = pd.DataFrame()
|
||||
dd_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", stock=stock
|
||||
result_menu = dd_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", stock=stock, queue=None
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
)
|
||||
dd.print_help()
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "dd"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
result = dd.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
)
|
||||
result = dd.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
)
|
||||
result = dd.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "dd"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "dd", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = dd.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
ticker="", start="", interval="", stock=pd.DataFrame()
|
||||
)
|
||||
other_args = list()
|
||||
result = dd.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -159,7 +234,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_pt",
|
||||
"business_insider_view.price_target_from_analysts",
|
||||
["--num=10"],
|
||||
["--limit=10"],
|
||||
{
|
||||
"ticker": "TSLA",
|
||||
"start": "10/25/2021",
|
||||
@@ -182,7 +257,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_rot",
|
||||
"finnhub_view.rating_over_time",
|
||||
["--num=10"],
|
||||
["--limit=10"],
|
||||
{
|
||||
"ticker": "TSLA",
|
||||
"num": 10,
|
||||
@@ -193,7 +268,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_rating",
|
||||
"fmp_view.rating",
|
||||
["--num=10"],
|
||||
["--limit=10"],
|
||||
{
|
||||
"ticker": "TSLA",
|
||||
"num": 10,
|
||||
@@ -203,7 +278,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_sec",
|
||||
"marketwatch_view.sec_filings",
|
||||
["--num=10"],
|
||||
["--limit=10"],
|
||||
{
|
||||
"ticker": "TSLA",
|
||||
"num": 10,
|
||||
@@ -222,7 +297,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_arktrades",
|
||||
"ark_view.display_ark_trades",
|
||||
["--num=10", "--show_ticker"],
|
||||
["--limit=10", "--show_ticker"],
|
||||
{
|
||||
"ticker": "TSLA",
|
||||
"num": 10,
|
||||
@@ -238,13 +313,13 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller." + mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
stock=None,
|
||||
)
|
||||
getattr(dd, tested_func)(other_args=other_args)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
if isinstance(called_with, dict):
|
||||
mock.assert_called_once_with(**called_with)
|
||||
@@ -274,10 +349,11 @@ def test_call_func_no_parser(func, mocker):
|
||||
"gamestonk_terminal.stocks.due_diligence.dd_controller.parse_known_args_and_warn",
|
||||
return_value=None,
|
||||
)
|
||||
dd = dd_controller.DueDiligenceController(
|
||||
controller = dd_controller.DueDiligenceController(
|
||||
ticker="AAPL", start="10/25/2021", interval="1440min", stock=pd.DataFrame()
|
||||
)
|
||||
|
||||
func_result = getattr(dd, func)(other_args=list())
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(dd_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
|
||||
Due Diligence:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load new ticker
|
||||
|
||||
Ticker:
|
||||
|
||||
Finviz:
|
||||
|
||||
@@ -13,33 +13,76 @@ from gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep impo
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["profile", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.session"
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller."
|
||||
"FinancialModelingPrepController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = fmp_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=fmp_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
result_menu = fmp_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", queue=None
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@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):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=fmp_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_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
|
||||
@@ -48,105 +91,133 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
financial_modeling_prep = (
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep"
|
||||
)
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch(financial_modeling_prep + ".fmp_controller.session")
|
||||
mocker.patch(
|
||||
financial_modeling_prep + ".fmp_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
financial_modeling_prep
|
||||
+ ".fmp_controller.FinancialModelingPrepController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller."
|
||||
"FinancialModelingPrepController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
fmp_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
result_menu = fmp_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", queue=None
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
)
|
||||
fmp.print_help()
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "quit", "reset", "stocks", "fa", "fmp"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
queue=None,
|
||||
)
|
||||
result = fmp.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
)
|
||||
result = fmp.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
)
|
||||
result = fmp.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
"reset",
|
||||
"stocks",
|
||||
"load MOCK_TICKER",
|
||||
"fa",
|
||||
"fmp",
|
||||
],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
"reset",
|
||||
"stocks",
|
||||
"load MOCK_TICKER",
|
||||
"fa",
|
||||
"fmp",
|
||||
"help",
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="MOCK_TICKER",
|
||||
start="",
|
||||
interval="",
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = fmp.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
fmp = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
)
|
||||
other_args = list()
|
||||
result = fmp.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -168,49 +239,49 @@ def test_call_quit():
|
||||
(
|
||||
"call_enterprise",
|
||||
"fmp_view.display_enterprise",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_dcf",
|
||||
"fmp_view.display_discounted_cash_flow",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_income",
|
||||
"fmp_view.display_income_statement",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_balance",
|
||||
"fmp_view.display_balance_sheet",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_cash",
|
||||
"fmp_view.display_cash_flow",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_metrics",
|
||||
"fmp_view.display_key_metrics",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_ratios",
|
||||
"fmp_view.display_financial_ratios",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_growth",
|
||||
"fmp_view.display_financial_statement_growth",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
],
|
||||
@@ -222,12 +293,12 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
+ mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
fa = fmp_controller.FinancialModelingPrepController(
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
)
|
||||
getattr(fa, tested_func)(other_args=other_args)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
if isinstance(called_with, dict):
|
||||
mock.assert_called_once_with(**called_with)
|
||||
@@ -258,12 +329,13 @@ def test_call_func_no_parser(func, mocker):
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.parse_known_args_and_warn",
|
||||
return_value=None,
|
||||
)
|
||||
fa = fmp_controller.FinancialModelingPrepController(
|
||||
controller = fmp_controller.FinancialModelingPrepController(
|
||||
ticker="AAPL",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
)
|
||||
|
||||
func_result = getattr(fa, func)(other_args=list())
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(fmp_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
|
||||
Financial Modeling Prep:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
Financial Modeling Prep Menu:
|
||||
|
||||
Ticker:
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ def test_check_output(func, kwargs_dict, monkeypatch, use_tab):
|
||||
getattr(av_view, func)(**kwargs_dict)
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -11,32 +11,78 @@ from gamestonk_terminal.stocks.fundamental_analysis import fa_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session.prompt",
|
||||
return_value="quit",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.fa_controller."
|
||||
"FundamentalAnalysisController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
|
||||
result_menu = fa_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
suffix="",
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=fa_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = fa_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", suffix="", queue=None
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@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):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=fa_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.fundamental_analysis.fa_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
|
||||
@@ -45,108 +91,118 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.fa_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.fa_controller.FundamentalAnalysisController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.fa_controller."
|
||||
"FundamentalAnalysisController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
fa_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
suffix="",
|
||||
result_menu = fa_controller.menu(
|
||||
ticker="TSLA", start="10/25/2021", interval="1440min", suffix="", queue=None
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
controller = fa_controller.FundamentalAnalysisController(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
suffix="",
|
||||
)
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "fa"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
suffix="",
|
||||
queue=None,
|
||||
)
|
||||
dd.print_help()
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
suffix="",
|
||||
)
|
||||
result = dd.switch(an_input="")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
suffix="",
|
||||
)
|
||||
result = dd.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
controller = fa_controller.FundamentalAnalysisController(
|
||||
ticker="TSLA",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
suffix="",
|
||||
)
|
||||
result = dd.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "fa"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "fa", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
suffix="",
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = dd.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
dd = fa_controller.FundamentalAnalysisController(
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
suffix="",
|
||||
)
|
||||
other_args = list()
|
||||
result = dd.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -228,26 +284,26 @@ def test_call_quit():
|
||||
(
|
||||
"call_income",
|
||||
"av_view.display_income_statement",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "limit": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_balance",
|
||||
"av_view.display_balance_sheet",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "limit": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_cash",
|
||||
"av_view.display_cash_flow",
|
||||
["--export=csv", "--num=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True, "export": "csv"},
|
||||
["--export=csv", "--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "limit": 5, "quarterly": True, "export": "csv"},
|
||||
),
|
||||
(
|
||||
"call_earnings",
|
||||
"av_view.display_earnings",
|
||||
["--num=5", "--quarter"],
|
||||
{"ticker": "TSLA", "number": 5, "quarterly": True},
|
||||
["--limit=5", "--quarter"],
|
||||
{"ticker": "TSLA", "limit": 5, "quarterly": True},
|
||||
),
|
||||
(
|
||||
"call_fraud",
|
||||
@@ -345,22 +401,19 @@ def test_key_metrics_explained_no_parser(mocker):
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"expected, mock_menu",
|
||||
[(None, False), (True, True)],
|
||||
)
|
||||
def test_call_fmp(expected, mock_menu, mocker):
|
||||
def test_call_fmp(mocker):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.fundamental_analysis.financial_modeling_prep.fmp_controller.menu",
|
||||
return_value=mock_menu,
|
||||
return_value=["quit"],
|
||||
)
|
||||
|
||||
fa = fa_controller.FundamentalAnalysisController(
|
||||
controller = fa_controller.FundamentalAnalysisController(
|
||||
ticker="AAPL",
|
||||
start="10/25/2021",
|
||||
interval="1440min",
|
||||
suffix="",
|
||||
)
|
||||
|
||||
mocker.patch.object(fa, "print_help", autospec=True)
|
||||
assert fa.call_fmp(list()) is expected
|
||||
mocker.patch.object(controller, "print_help", autospec=True)
|
||||
controller.call_fmp(list())
|
||||
assert controller.queue == ["quit"]
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
Error getting earnings data.
|
||||
No API calls left. Try me later
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
Issue getting key metrics from alpha vantage.
|
||||
No API calls left. Try me later
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
No data found from alphavantage for TSLA.
|
||||
No API calls left. Try me later
|
||||
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
|
||||
Fundamental Analysis:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load a new ticker
|
||||
Ticker:
|
||||
Ticker: TSLA
|
||||
|
||||
data fundamental and technical data of company [FinViz]
|
||||
mgmt management team of the company [Business Insider]
|
||||
|
||||
58
tests/gamestonk_terminal/stocks/government/cassettes/test_gov_controller/test_call_load.yaml
vendored
Normal file
58
tests/gamestonk_terminal/stocks/government/cassettes/test_gov_controller/test_call_load.yaml
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
interactions:
|
||||
- request:
|
||||
body: null
|
||||
headers:
|
||||
Accept:
|
||||
- '*/*'
|
||||
Accept-Encoding:
|
||||
- gzip, deflate
|
||||
Connection:
|
||||
- keep-alive
|
||||
method: GET
|
||||
uri: https://query2.finance.yahoo.com/v8/finance/chart/TSLA?events=div%2Csplits&includePrePost=False&interval=1d&period1=1598220000&period2=1635980400
|
||||
response:
|
||||
body:
|
||||
string: '{"chart":{"result":[{"meta":{"currency":"USD","symbol":"TSLA","exchangeName":"NMS","instrumentType":"EQUITY","firstTradeDate":1277818200,"regularMarketTime":1640293203,"gmtoffset":-18000,"timezone":"EST","exchangeTimezoneName":"America/New_York","regularMarketPrice":1067.0,"chartPreviousClose":926.92,"priceHint":2,"currentTradingPeriod":{"pre":{"timezone":"EST","end":1640269800,"start":1640250000,"gmtoffset":-18000},"regular":{"timezone":"EST","end":1640293200,"start":1640269800,"gmtoffset":-18000},"post":{"timezone":"EST","end":1640307600,"start":1640293200,"gmtoffset":-18000}},"dataGranularity":"1d","range":"","validRanges":["1d","5d","1mo","3mo","6mo","1y","2y","5y","10y","ytd","max"]},"timestamp":[1639665000,1639751400,1640010600,1640097000,1640183400,1640269800],"indicators":{"quote":[{"high":[994.97998046875,960.6599731445312,921.6900024414062,939.5,1015.6599731445312,1072.97998046875],"close":[926.9199829101562,932.5700073242188,899.9400024414062,938.530029296875,1008.8699951171875,1067.0],"low":[921.8499755859375,909.0399780273438,893.3900146484375,886.1199951171875,957.0499877929688,997.5599975585938],"open":[994.5,914.77001953125,910.7000122070312,916.8699951171875,965.6599731445312,1006.7999877929688],"volume":[27590500,33479100,18826700,23839300,31211400,30904400]}],"adjclose":[{"adjclose":[926.9199829101562,932.5700073242188,899.9400024414062,938.530029296875,1008.8699951171875,1067.0]}]}}],"error":null}}'
|
||||
headers:
|
||||
Age:
|
||||
- '3'
|
||||
Connection:
|
||||
- keep-alive
|
||||
Expect-CT:
|
||||
- max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"
|
||||
Referrer-Policy:
|
||||
- no-referrer-when-downgrade
|
||||
Strict-Transport-Security:
|
||||
- max-age=15552000
|
||||
X-Content-Type-Options:
|
||||
- nosniff
|
||||
X-Frame-Options:
|
||||
- SAMEORIGIN
|
||||
X-XSS-Protection:
|
||||
- 1; mode=block
|
||||
cache-control:
|
||||
- public, max-age=10, stale-while-revalidate=20
|
||||
content-length:
|
||||
- '1441'
|
||||
content-type:
|
||||
- application/json;charset=utf-8
|
||||
date:
|
||||
- Sat, 25 Dec 2021 01:03:49 GMT
|
||||
server:
|
||||
- ATS
|
||||
vary:
|
||||
- Origin,Accept-Encoding
|
||||
x-envoy-decorator-operation:
|
||||
- finance-chart-api--mtls-production-ir2.finance-k8s.svc.yahoo.local:4080/*
|
||||
x-envoy-upstream-service-time:
|
||||
- '4'
|
||||
x-request-id:
|
||||
- 66f52e27-a58f-4c10-a566-5eab8836b0ac
|
||||
x-yahoo-request-id:
|
||||
- fkfrg1pgscrfl
|
||||
y-rid:
|
||||
- fkfrg1pgscrfl
|
||||
status:
|
||||
code: 200
|
||||
message: OK
|
||||
version: 1
|
||||
@@ -11,27 +11,87 @@ from gamestonk_terminal.stocks.government import gov_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
return {
|
||||
"filter_headers": [("User-Agent", None)],
|
||||
"filter_query_parameters": [
|
||||
("period1", "1598220000"),
|
||||
("period2", "1635980400"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.government.gov_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.government.gov_controller.session.prompt",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.government.gov_controller."
|
||||
"GovController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = gov_controller.menu(
|
||||
ticker="TSLA",
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=gov_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.government.gov_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.government.gov_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = gov_controller.menu(ticker="TSLA")
|
||||
result_menu = gov_controller.menu(
|
||||
ticker="TSLA",
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["help", "homee help", "home help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=gov_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.government.gov_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
|
||||
@@ -40,73 +100,107 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.government.gov_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.government.gov_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.government.gov_controller.GovController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.government.gov_controller."
|
||||
"GovController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
gov_controller.menu(ticker="TSLA")
|
||||
result_menu = gov_controller.menu(
|
||||
ticker="TSLA",
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
dd.print_help()
|
||||
controller = gov_controller.GovController(
|
||||
ticker="",
|
||||
)
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
result = dd.switch(an_input="")
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "gov"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = gov_controller.GovController(
|
||||
ticker="",
|
||||
queue=None,
|
||||
)
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
result = dd.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
result = dd.switch(an_input="cls")
|
||||
controller = gov_controller.GovController(
|
||||
ticker="",
|
||||
)
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
other_args = list()
|
||||
result = dd.call_q(other_args)
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "gov"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "gov", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = gov_controller.GovController(
|
||||
ticker="",
|
||||
queue=queue,
|
||||
)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
dd = gov_controller.GovController(ticker="")
|
||||
other_args = list()
|
||||
result = dd.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -116,37 +210,45 @@ def test_call_quit():
|
||||
(
|
||||
"call_contracts",
|
||||
"quiverquant_view.display_contracts",
|
||||
["--past_transaction_days=5", "--raw"],
|
||||
["--past_transaction_days=5", "--raw", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
past_transaction_days=5,
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
"call_gtrades",
|
||||
"quiverquant_view.display_government_trading",
|
||||
["--past_transactions_months=5", "--govtype=congress", "--raw"],
|
||||
[
|
||||
"--past_transactions_months=5",
|
||||
"--govtype=congress",
|
||||
"--raw",
|
||||
"--export=csv",
|
||||
],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
gov_type="congress",
|
||||
past_transactions_months=5,
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
"call_histcont",
|
||||
"quiverquant_view.display_hist_contracts",
|
||||
["--export=csv"],
|
||||
["--raw", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
"call_lastcontracts",
|
||||
"quiverquant_view.display_last_contracts",
|
||||
["--past_transaction_days=2", "--num=5", "--sum", "--export=csv"],
|
||||
["--past_transaction_days=2", "--limit=5", "--sum", "--export=csv"],
|
||||
dict(
|
||||
past_transaction_days=2,
|
||||
num=5,
|
||||
@@ -173,7 +275,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_lobbying",
|
||||
"quiverquant_view.display_lobbying",
|
||||
["--num=5"],
|
||||
["--limit=5"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=5,
|
||||
@@ -182,10 +284,12 @@ def test_call_quit():
|
||||
(
|
||||
"call_qtrcontracts",
|
||||
"quiverquant_view.display_qtr_contracts",
|
||||
["--num=5", "--analysis=total"],
|
||||
["--limit=5", "--analysis=total", "--raw", "--export=csv"],
|
||||
dict(
|
||||
analysis="total",
|
||||
num=5,
|
||||
raw=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
@@ -194,7 +298,7 @@ def test_call_quit():
|
||||
[
|
||||
"--govtype=congress",
|
||||
"--past_transactions_months=2",
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--raw",
|
||||
"--export=csv",
|
||||
],
|
||||
@@ -209,7 +313,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_toplobbying",
|
||||
"quiverquant_view.display_top_lobbying",
|
||||
["--num=5", "--raw", "--export=csv"],
|
||||
["--limit=5", "--raw", "--export=csv"],
|
||||
dict(
|
||||
num=5,
|
||||
raw=True,
|
||||
@@ -222,7 +326,7 @@ def test_call_quit():
|
||||
[
|
||||
"--govtype=congress",
|
||||
"--past_transactions_months=2",
|
||||
"--num=5",
|
||||
"--limit=5",
|
||||
"--raw",
|
||||
"--export=csv",
|
||||
],
|
||||
@@ -279,17 +383,47 @@ def test_call_func_no_parser(func, mocker):
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(gov_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_move="none")
|
||||
@pytest.mark.record_stdout
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"expected, ticker",
|
||||
[(True, "MOCK_TYPE"), (False, None)],
|
||||
"func",
|
||||
[
|
||||
"call_gtrades",
|
||||
"call_contracts",
|
||||
"call_histcont",
|
||||
"call_lobbying",
|
||||
],
|
||||
)
|
||||
def test_check_ticker(expected, ticker):
|
||||
controller = gov_controller.GovController(ticker=ticker)
|
||||
def test_call_func_no_ticker(func, mocker):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.government.gov_controller.parse_known_args_and_warn",
|
||||
return_value=True,
|
||||
)
|
||||
controller = gov_controller.GovController(ticker=None)
|
||||
|
||||
# pylint: disable=protected-access
|
||||
assert controller._check_ticker() == expected
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(gov_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr
|
||||
def test_call_load(mocker):
|
||||
yf_download = gov_controller.stocks_helper.yf.download
|
||||
|
||||
def mock_yf_download(*args, **kwargs):
|
||||
kwargs["threads"] = False
|
||||
return yf_download(*args, **kwargs)
|
||||
|
||||
mocker.patch("yfinance.download", side_effect=mock_yf_download)
|
||||
controller = gov_controller.GovController(
|
||||
ticker="TSLA",
|
||||
)
|
||||
other_args = [
|
||||
"TSLA",
|
||||
"--start=2021-12-17",
|
||||
]
|
||||
controller.call_load(other_args=other_args)
|
||||
|
||||
@@ -7,8 +7,6 @@ import pytest
|
||||
# IMPORTATION INTERNAL
|
||||
from gamestonk_terminal.stocks.government import quiverquant_view
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
@@ -73,8 +71,11 @@ def vcr_config():
|
||||
],
|
||||
)
|
||||
def test_call_func(func, kwargs_dict, mocker, use_tab):
|
||||
mocker.patch(target="matplotlib.pyplot.show", new=mocker.Mock())
|
||||
mocker.patch.object(target=quiverquant_view.gtff, attribute="USE_ION", new=False)
|
||||
mocker.patch.object(target=quiverquant_view.gtff, attribute="USE_ION", new=True)
|
||||
mocker.patch(target="gamestonk_terminal.stocks.government.quiverquant_view.plt.ion")
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.government.quiverquant_view.plt.show"
|
||||
)
|
||||
mocker.patch.object(
|
||||
target=quiverquant_view.gtff, attribute="USE_TABULATE_DF", new=use_tab
|
||||
)
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
No ticker loaded. Use `load <ticker>` first.
|
||||
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
|
||||
Government:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load a ticker
|
||||
|
||||
Explore:
|
||||
lasttrades last trades
|
||||
topbuys show most purchased stocks
|
||||
@@ -14,6 +7,8 @@ Explore:
|
||||
qtrcontracts quarterly government contracts analysis
|
||||
toplobbying top corporate lobbying tickers
|
||||
|
||||
load load a specific ticker for analysis
|
||||
|
||||
Ticker: None[2m
|
||||
|
||||
gtrades show government trades for ticker
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
1250 NYRT
|
||||
1418 REGN
|
||||
|
||||
|
||||
@@ -1,8 +1 @@
|
||||
╒═══════════╕
|
||||
│ tickers │
|
||||
╞═══════════╡
|
||||
│ NYRT │
|
||||
├───────────┤
|
||||
│ REGN │
|
||||
╘═══════════╛
|
||||
|
||||
|
||||
@@ -12,34 +12,97 @@ from gamestonk_terminal.stocks.insider import insider_controller
|
||||
# pylint: disable=W0603
|
||||
# pylint: disable=E1111
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
EMPTY_DF = pd.DataFrame()
|
||||
|
||||
empty_df = pd.DataFrame()
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def vcr_config():
|
||||
return {
|
||||
"filter_headers": [("User-Agent", None)],
|
||||
"filter_query_parameters": [
|
||||
("period1", "1598220000"),
|
||||
("period2", "1635980400"),
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.insider.insider_controller.session")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["load", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.insider.insider_controller.session.prompt",
|
||||
return_value="quit",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.insider.insider_controller."
|
||||
"InsiderController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
|
||||
stock = pd.DataFrame()
|
||||
result_menu = insider_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
stock=stock,
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=insider_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.insider.insider_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.insider.insider_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
stock = pd.DataFrame()
|
||||
result_menu = insider_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=stock,
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@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):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=insider_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.insider.insider_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
|
||||
@@ -48,108 +111,123 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch("gamestonk_terminal.stocks.insider.insider_controller.session")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.insider.insider_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.insider.insider_controller.InsiderController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.insider.insider_controller."
|
||||
"InsiderController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
insider_controller.menu(
|
||||
stock = pd.DataFrame()
|
||||
result_menu = insider_controller.menu(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
stock=stock,
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
controller.print_help()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "ins"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
queue=None,
|
||||
)
|
||||
result = controller.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
result = controller.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "ins"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "ins", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
ticker="",
|
||||
start="",
|
||||
interval="",
|
||||
stock=pd.DataFrame(),
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="TSLA",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -159,129 +237,135 @@ def test_call_quit():
|
||||
(
|
||||
"call_filter",
|
||||
"openinsider_view.print_insider_filter",
|
||||
list(),
|
||||
[list(), "template"],
|
||||
["--limit=1", "--urls", "--export=csv"],
|
||||
dict(
|
||||
preset_loaded="whales",
|
||||
ticker="",
|
||||
limit=1,
|
||||
links=True,
|
||||
export="csv",
|
||||
),
|
||||
),
|
||||
(
|
||||
"call_lcb",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "lcb"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["lcb", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_lpsb",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "lpsb"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["lpsb", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_lit",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "lit"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["lit", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_lip",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "lip"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["lip", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blip",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blip"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blip", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blop",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blop"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blop", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blcp",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blcp"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blcp", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_lis",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "lis"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["lis", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blis",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blis"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blis", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blos",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blos"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blos", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_blcs",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "blcs"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["blcs", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_topt",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "topt"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["topt", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_toppw",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "toppw"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["toppw", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_toppm",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "toppm"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["toppm", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_tipt",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "tipt"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["tipt", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_tippw",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "tippw"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["tippw", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_tippm",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "tippm"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["tippm", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_tist",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "tist"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["tist", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_tispw",
|
||||
"openinsider_view.print_insider_data",
|
||||
list(),
|
||||
[list(), "tispw"],
|
||||
["--limit=1", "--export=csv"],
|
||||
["tispw", 1, "csv"],
|
||||
),
|
||||
(
|
||||
"call_act",
|
||||
"businessinsider_view.insider_activity",
|
||||
["--num=5", "--raw", "--export=csv"],
|
||||
["--limit=5", "--raw", "--export=csv"],
|
||||
dict(
|
||||
stock=empty_df,
|
||||
stock=EMPTY_DF,
|
||||
ticker="MOCK_TICKER",
|
||||
start="MOCK_DATE",
|
||||
interval="MOCK_INTERVAL",
|
||||
@@ -293,7 +377,7 @@ def test_call_quit():
|
||||
(
|
||||
"call_lins",
|
||||
"finviz_view.last_insider_activity",
|
||||
["--num=5", "--export=csv"],
|
||||
["--limit=5", "--export=csv"],
|
||||
dict(
|
||||
ticker="MOCK_TICKER",
|
||||
num=5,
|
||||
@@ -308,12 +392,12 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"gamestonk_terminal.stocks.insider.insider_controller." + mocked_func,
|
||||
new=mock,
|
||||
)
|
||||
empty_df.drop(empty_df.index, inplace=True)
|
||||
EMPTY_DF.drop(EMPTY_DF.index, inplace=True)
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="MOCK_TICKER",
|
||||
start="MOCK_DATE",
|
||||
interval="MOCK_INTERVAL",
|
||||
stock=empty_df,
|
||||
stock=EMPTY_DF,
|
||||
)
|
||||
getattr(controller, tested_func)(other_args=other_args)
|
||||
|
||||
@@ -332,8 +416,6 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"call_load",
|
||||
"call_act",
|
||||
"call_lins",
|
||||
"view_available_presets",
|
||||
"set_preset",
|
||||
],
|
||||
)
|
||||
def test_call_func_no_parser(func, mocker):
|
||||
@@ -350,16 +432,18 @@ def test_call_func_no_parser(func, mocker):
|
||||
|
||||
func_result = getattr(controller, func)(other_args=list())
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(insider_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@pytest.mark.parametrize(
|
||||
"func",
|
||||
["call_act", "call_lins"],
|
||||
)
|
||||
def test_call_func_empty_df(func):
|
||||
def test_call_func_EMPTY_DF(func):
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker=None,
|
||||
start="2021-10-25",
|
||||
@@ -383,42 +467,3 @@ def test_call_func_empty_ticker(func):
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
getattr(controller, func)(other_args=list())
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.parametrize(
|
||||
"func, mocked_func",
|
||||
[
|
||||
("call_view", "view_available_presets"),
|
||||
("call_set", "set_preset"),
|
||||
],
|
||||
)
|
||||
def test_call_method(func, mocked_func, mocker):
|
||||
controller_path = (
|
||||
"gamestonk_terminal.stocks.insider.insider_controller.InsiderController."
|
||||
)
|
||||
mocker.patch(controller_path + mocked_func)
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker=None,
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
getattr(controller, func)(other_args=list())
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
@pytest.mark.parametrize(
|
||||
"func",
|
||||
["view_available_presets", "set_preset"],
|
||||
)
|
||||
def test_call_staticmethod(func):
|
||||
controller = insider_controller.InsiderController(
|
||||
ticker="MOCK_TICKER",
|
||||
start="2021-10-25",
|
||||
interval="1440min",
|
||||
stock=pd.DataFrame(),
|
||||
)
|
||||
other_args = ["--preset=template"]
|
||||
getattr(controller, func)(other_args=other_args)
|
||||
|
||||
@@ -8,8 +8,6 @@ from gamestonk_terminal.stocks.insider import openinsider_view
|
||||
|
||||
# pylint: disable=E1101
|
||||
|
||||
pytest.skip(allow_module_level=True)
|
||||
|
||||
|
||||
@pytest.mark.vcr
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
No ticker loaded. First use `load {ticker}`
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
|
||||
Insider Trading:
|
||||
cls clear screen
|
||||
?/help show this menu again
|
||||
q quit this menu, and shows back to main menu
|
||||
quit quit to abandon program
|
||||
load load a specific stock ticker for analysis
|
||||
|
||||
PRESET: template
|
||||
view view available presets
|
||||
set set one of the available presets
|
||||
|
||||
PRESET: whales
|
||||
|
||||
filter filter insiders based on preset
|
||||
|
||||
Latest:
|
||||
load load a specific stock ticker for analysis
|
||||
[2m
|
||||
Ticker:
|
||||
|
||||
stats insider stats of the company [Open Insider]
|
||||
act insider activity over time [Business Insider]
|
||||
lins last insider trading of the company [Finviz]
|
||||
[0m
|
||||
Latest Insiders:
|
||||
lcb latest cluster boys
|
||||
lpsb latest penny stock buys
|
||||
lit latest insider trading (all filings)
|
||||
@@ -23,7 +26,7 @@ Latest:
|
||||
blis big latest insider sales ($100k+)
|
||||
blos big latest officer sales ($100k+)
|
||||
blcs big latest CEO/CFO sales ($100k+)
|
||||
Top:
|
||||
Top Insiders:
|
||||
topt top officer purchases today
|
||||
toppw top officer purchases past week
|
||||
toppm top officer purchases past month
|
||||
@@ -34,8 +37,3 @@ Top:
|
||||
tispw top insider sales past week
|
||||
tispm top insider sales past month
|
||||
|
||||
Ticker: TSLA
|
||||
|
||||
act insider activity over time [Business Insider]
|
||||
lins last insider trading of the company [Finviz]
|
||||
|
||||
|
||||
@@ -56,14 +56,45 @@ PRED_CONTROLLER = pred_controller.PredictionTechniquesController(
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_quick_exit(mocker):
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
@pytest.mark.parametrize(
|
||||
"queue, expected",
|
||||
[
|
||||
(["pick", "help"], []),
|
||||
(["quit", "help"], ["help"]),
|
||||
],
|
||||
)
|
||||
def test_menu_with_queue(expected, mocker, queue):
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller.session"
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller."
|
||||
"PredictionTechniquesController.switch"
|
||||
),
|
||||
return_value=["quit"],
|
||||
)
|
||||
result_menu = pred_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=queue,
|
||||
)
|
||||
|
||||
assert result_menu == expected
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_menu_without_queue_completion(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=pred_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller.session.prompt",
|
||||
target="gamestonk_terminal.stocks.prediction_techniques.pred_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.prediction_techniques.pred_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
@@ -72,14 +103,33 @@ def test_menu_quick_exit(mocker):
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_menu_system_exit(mocker):
|
||||
@pytest.mark.parametrize(
|
||||
"mock_input",
|
||||
["picked", "load help", "mock"],
|
||||
)
|
||||
def test_menu_without_queue_sys_exit(mock_input, mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=pred_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=False,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.prediction_techniques.pred_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
|
||||
@@ -88,36 +138,41 @@ def test_menu_system_exit(mocker):
|
||||
if self.first_call:
|
||||
self.first_call = False
|
||||
raise SystemExit()
|
||||
return True
|
||||
return ["quit"]
|
||||
|
||||
mock_switch = mocker.Mock(side_effect=SystemExitSideEffect())
|
||||
mocker.patch("builtins.input", return_value="quit")
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller.session"
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
mocker.patch(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller.PredictionTechniquesController.switch",
|
||||
target=(
|
||||
"gamestonk_terminal.stocks.prediction_techniques.pred_controller."
|
||||
"PredictionTechniquesController.switch"
|
||||
),
|
||||
new=mock_switch,
|
||||
)
|
||||
|
||||
pred_controller.menu(
|
||||
result_menu = pred_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_print_help():
|
||||
@pytest.mark.parametrize(
|
||||
"start",
|
||||
[
|
||||
None,
|
||||
datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
],
|
||||
)
|
||||
def test_print_help(start):
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
start=start,
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
)
|
||||
@@ -125,34 +180,32 @@ def test_print_help():
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_empty():
|
||||
@pytest.mark.parametrize(
|
||||
"an_input, expected_queue",
|
||||
[
|
||||
("", []),
|
||||
("/help", ["quit", "quit", "help"]),
|
||||
("help/help", ["help"]),
|
||||
("q", ["quit"]),
|
||||
("h", []),
|
||||
("r", ["quit", "quit", "reset", "stocks", "load TSLA", "pred"]),
|
||||
],
|
||||
)
|
||||
def test_switch(an_input, expected_queue):
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=None,
|
||||
)
|
||||
result = controller.switch(an_input="")
|
||||
queue = controller.switch(an_input=an_input)
|
||||
|
||||
assert result is None
|
||||
assert queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@pytest.mark.record_stdout
|
||||
def test_switch_help():
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
)
|
||||
result = controller.switch(an_input="?")
|
||||
|
||||
assert result is None
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_switch_cls(mocker):
|
||||
def test_call_cls(mocker):
|
||||
mocker.patch("os.system")
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
@@ -160,38 +213,54 @@ def test_switch_cls(mocker):
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
)
|
||||
result = controller.switch(an_input="cls")
|
||||
controller.call_cls([])
|
||||
|
||||
assert result is None
|
||||
assert controller.queue == []
|
||||
os.system.assert_called_once_with("cls||clear")
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_q():
|
||||
@pytest.mark.parametrize(
|
||||
"func, queue, expected_queue",
|
||||
[
|
||||
(
|
||||
"call_exit",
|
||||
[],
|
||||
[
|
||||
"quit",
|
||||
"quit",
|
||||
"quit",
|
||||
],
|
||||
),
|
||||
("call_exit", ["help"], ["quit", "quit", "quit", "help"]),
|
||||
("call_home", [], ["quit", "quit"]),
|
||||
("call_help", [], []),
|
||||
("call_quit", [], ["quit"]),
|
||||
("call_quit", ["help"], ["quit", "help"]),
|
||||
(
|
||||
"call_reset",
|
||||
[],
|
||||
["quit", "quit", "reset", "stocks", "load TSLA", "pred"],
|
||||
),
|
||||
(
|
||||
"call_reset",
|
||||
["help"],
|
||||
["quit", "quit", "reset", "stocks", "load TSLA", "pred", "help"],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_call_func_expect_queue(expected_queue, queue, func):
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=queue,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_q(other_args)
|
||||
result = getattr(controller, func)([])
|
||||
|
||||
assert result is False
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_quit():
|
||||
controller = pred_controller.PredictionTechniquesController(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
)
|
||||
other_args = list()
|
||||
result = controller.call_quit(other_args)
|
||||
|
||||
assert result is True
|
||||
assert result is None
|
||||
assert controller.queue == expected_queue
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
@@ -438,6 +507,7 @@ def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
|
||||
"func",
|
||||
[
|
||||
"call_load",
|
||||
"call_pick",
|
||||
"call_ets",
|
||||
"call_knn",
|
||||
"call_regression",
|
||||
@@ -470,4 +540,32 @@ def test_call_func_no_parser(func, mocker):
|
||||
|
||||
func_result = getattr(controller, func)(other_args=["PM"])
|
||||
assert func_result is None
|
||||
assert controller.queue == []
|
||||
getattr(pred_controller, "parse_known_args_and_warn").assert_called_once()
|
||||
|
||||
|
||||
@pytest.mark.vcr(record_mode="none")
|
||||
def test_call_load(mocker):
|
||||
# DISABLE AUTO-COMPLETION
|
||||
mocker.patch.object(
|
||||
target=pred_controller.gtff,
|
||||
attribute="USE_PROMPT_TOOLKIT",
|
||||
new=True,
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.prediction_techniques.pred_controller.session",
|
||||
)
|
||||
mocker.patch(
|
||||
target="gamestonk_terminal.stocks.prediction_techniques.pred_controller.session.prompt",
|
||||
return_value="quit",
|
||||
)
|
||||
|
||||
result_menu = pred_controller.menu(
|
||||
ticker="TSLA",
|
||||
start=datetime.strptime("2020-12-01", "%Y-%m-%d"),
|
||||
interval="1440min",
|
||||
stock=DF_STOCK,
|
||||
queue=None,
|
||||
)
|
||||
|
||||
assert result_menu == []
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Prediction Techniques Menu:
|
||||
|
||||
load load new ticker
|
||||
pick pick new target variable
|
||||
|
||||
Ticker Loaded: {s_intraday} Stock: {self.ticker}
|
||||
Target Column: AdjClose
|
||||
|
||||
Models:
|
||||
ets exponential smoothing (e.g. Holt-Winters)
|
||||
knn k-Nearest Neighbors
|
||||
regression polynomial regression
|
||||
arima autoregressive integrated moving average
|
||||
mlp MultiLayer Perceptron
|
||||
rnn Recurrent Neural Network
|
||||
lstm Long-Short Term Memory
|
||||
conv1d 1D Convolutional Neural Network
|
||||
mc Monte-Carlo simulations
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
Prediction Techniques Menu:
|
||||
|
||||
load load new ticker
|
||||
pick pick new target variable
|
||||
|
||||
Ticker Loaded: Daily Stock: TSLA (from 2020-12-01)
|
||||
Target Column: AdjClose
|
||||
|
||||
Models:
|
||||
ets exponential smoothing (e.g. Holt-Winters)
|
||||
knn k-Nearest Neighbors
|
||||
regression polynomial regression
|
||||
arima autoregressive integrated moving average
|
||||
mlp MultiLayer Perceptron
|
||||
rnn Recurrent Neural Network
|
||||
lstm Long-Short Term Memory
|
||||
conv1d 1D Convolutional Neural Network
|
||||
mc Monte-Carlo simulations
|
||||
|
||||
Reference in New Issue
Block a user