def test_print_help(): controller = qa_controller.QaController( ticker="", start="", interval="", stock=DF_STOCK.copy(), ) controller.print_help()
def test_switch(an_input, expected_queue): controller = qa_controller.QaController( ticker="", start="", interval="", stock=DF_STOCK.copy(), queue=None, ) queue = controller.switch(an_input=an_input) assert queue == expected_queue
def test_custom_reset(expected, ticker): controller = qa_controller.QaController( ticker=None, start="MOCK_DATE", interval="MOCK_INTERVAL", stock=DF_STOCK.copy(), ) controller.ticker = ticker result = controller.custom_reset() assert result == expected
def test_call_func_expect_queue(expected_queue, queue, func): controller = qa_controller.QaController( ticker="MOCK_TICKER", start="", interval="", stock=DF_STOCK.copy(), queue=queue, ) result = getattr(controller, func)([]) assert result is None assert controller.queue == expected_queue
def test_call_cls(mocker): mocker.patch("os.system") controller = qa_controller.QaController( ticker="", start="", interval="", stock=DF_STOCK.copy(), ) controller.call_cls([]) assert controller.queue == [] os.system.assert_called_once_with("cls||clear")
def test_menu_with_queue(expected, mocker, queue): mocker.patch( target=( "gamestonk_terminal.stocks.quantitative_analysis.qa_controller." "QaController.switch"), return_value=["quit"], ) result_menu = qa_controller.QaController( ticker="TSLA", start=datetime.strptime("2021-12-21", "%Y-%m-%d"), interval="1440min", stock=DF_STOCK.copy(), queue=queue, ).menu() assert result_menu == expected
def test_menu_without_queue_sys_exit(mock_input, mocker): # DISABLE AUTO-COMPLETION mocker.patch.object( target=qa_controller.gtff, attribute="USE_PROMPT_TOOLKIT", new=False, ) mocker.patch( target= "gamestonk_terminal.stocks.quantitative_analysis.qa_controller.session", return_value=None, ) # MOCK USER INPUT mocker.patch("builtins.input", return_value=mock_input) # MOCK SWITCH class SystemExitSideEffect: def __init__(self): self.first_call = True def __call__(self, *args, **kwargs): if self.first_call: self.first_call = False raise SystemExit() return ["quit"] mock_switch = mocker.Mock(side_effect=SystemExitSideEffect()) mocker.patch( target=( "gamestonk_terminal.stocks.quantitative_analysis.qa_controller." "QaController.switch"), new=mock_switch, ) result_menu = qa_controller.QaController( ticker="TSLA", start=datetime.strptime("2021-12-21", "%Y-%m-%d"), interval="1440min", stock=DF_STOCK.copy(), queue=None, ).menu() assert result_menu == []
def test_call_load(mocker): yf_download = parent_classes.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 = qa_controller.QaController( ticker="MOCK_TICKER", start="MOCK_DATE", interval="MOCK_INTERVAL", stock=DF_STOCK.copy(), ) other_args = [ "TSLA", "--start=2021-12-17", ] old_stock = controller.stock controller.call_load(other_args=other_args) assert not controller.stock.empty assert not controller.stock.equals(old_stock)
def test_menu_without_queue_completion(mocker): # ENABLE AUTO-COMPLETION : HELPER_FUNCS.MENU mocker.patch( target="gamestonk_terminal.feature_flags.USE_PROMPT_TOOLKIT", new=True, ) mocker.patch(target="gamestonk_terminal.parent_classes.session", ) mocker.patch( target="gamestonk_terminal.parent_classes.session.prompt", return_value="quit", ) # DISABLE AUTO-COMPLETION : CONTROLLER.COMPLETER mocker.patch.object( target=qa_controller.gtff, attribute="USE_PROMPT_TOOLKIT", new=True, ) mocker.patch( target= "gamestonk_terminal.stocks.quantitative_analysis.qa_controller.session", ) mocker.patch( target= "gamestonk_terminal.stocks.quantitative_analysis.qa_controller.session.prompt", return_value="quit", ) result_menu = qa_controller.QaController( ticker="TSLA", start=datetime.strptime("2021-12-21", "%Y-%m-%d"), interval="1440min", stock=DF_STOCK.copy(), queue=None, ).menu() assert result_menu == []
"High": 77.12999725341797, "Low": 75.69000244140625, "Close": 77.02999877929688, "Adj Close": 73.1242904663086, "Volume": 6791700, "date_id": 2, "OC_High": 77.02999877929688, "OC_Low": 76.0199966430664, }, }, orient="index", ) EMPTY_DF = pd.DataFrame() QA_CONTROLLER = qa_controller.QaController( ticker="MOCK_TICKER", start=datetime.strptime("2021-12-21", "%Y-%m-%d"), interval="MOCK_INTERVAL", stock=DF_STOCK.copy(), ) @pytest.fixture(scope="module") def vcr_config(): return { "filter_headers": [("User-Agent", None)], "filter_query_parameters": [ ("period1", "MOCK_PERIOD_1"), ("period2", "MOCK_PERIOD_2"), ("date", "MOCK_DATE"), ], }