def test_menu_without_queue_completion(mocker):
    # DISABLE AUTO-COMPLETION
    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.menu(
        ticker="TSLA",
        start=datetime.strptime("2021-12-21", "%Y-%m-%d"),
        interval="1440min",
        stock=DF_STOCK.copy(),
        queue=None,
    )

    assert result_menu == []
    def call_qa(self, _):
        """Process qa command"""
        if self.ticker:
            if self.interval == "1440min":
                from gamestonk_terminal.stocks.quantitative_analysis import (
                    qa_controller,
                )

                self.queue = qa_controller.menu(
                    self.ticker, self.start, self.interval, self.stock, self.queue
                )
            # TODO: This menu should work regardless of data being daily or not!
            print("Load daily data to use this menu!", "\n")
        else:
            print("Use 'load <ticker>' prior to this command!", "\n")
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.menu(
        ticker="TSLA",
        start=datetime.strptime("2021-12-21", "%Y-%m-%d"),
        interval="1440min",
        stock=DF_STOCK.copy(),
        queue=queue,
    )

    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.menu(
        ticker="TSLA",
        start=datetime.strptime("2021-12-21", "%Y-%m-%d"),
        interval="1440min",
        stock=DF_STOCK.copy(),
        queue=None,
    )

    assert result_menu == []
    def call_qa(self, _):
        """Process qa command"""
        if not self.ticker:
            print("Use 'load <ticker>' prior to this command!", "\n")
            return

        if self.interval != "1440min":
            # TODO: This menu should work regardless of data being daily or not!
            print("Load daily data to use this menu!", "\n")
            return

        ret = qa_controller.menu(
            self.ticker,
            self.start,
            self.interval,
            self.stock,
        )

        if ret is False:
            self.print_help()
        else:
            return True