示例#1
0
def test_call_po(mocker):
    similar = ["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"]
    mock = mocker.Mock(return_value=["MOCK_SIMILAR", "MOCK_USER"])
    target = "gamestonk_terminal.portfolio.portfolio_optimization.po_controller.PortfolioOptimization.menu"
    mocker.patch(target=target, new=mock)

    controller = ca_controller.ComparisonAnalysisController(similar=similar)
    controller.call_po([])
    mock.assert_called_once()

    controller = ca_controller.ComparisonAnalysisController()
    controller.call_po([])
    assert controller.queue == []
示例#2
0
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=ca_controller.gtff,
        attribute="USE_PROMPT_TOOLKIT",
        new=True,
    )
    mocker.patch(
        target=
        "gamestonk_terminal.stocks.comparison_analysis.ca_controller.session",
    )
    mocker.patch(
        target=
        "gamestonk_terminal.stocks.comparison_analysis.ca_controller.session.prompt",
        return_value="quit",
    )

    result_menu = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"],
        queue=None,
    ).menu()

    assert result_menu == []
示例#3
0
def test_call_cls(mocker):
    mocker.patch("os.system")
    controller = ca_controller.ComparisonAnalysisController()
    controller.call_cls([])

    assert controller.queue == []
    os.system.assert_called_once_with("cls||clear")
示例#4
0
def test_call_ticker(mocker):
    similar = ["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"]
    mock = mocker.Mock(return_value=pd.DataFrame())
    target = "yfinance.download"
    mocker.patch(target=target, new=mock)

    controller = ca_controller.ComparisonAnalysisController(similar=similar)
    controller.call_ticker(other_args=["MOCK_TICKER"])
    mock.assert_called_once_with("MOCK_TICKER", progress=False)
示例#5
0
def test_call_func_expect_queue(expected_queue, queue, func):
    controller = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR"],
        queue=queue,
    )
    result = getattr(controller, func)([])

    assert result is None
    assert controller.queue == expected_queue
示例#6
0
 def call_ca(self, _):
     """Process ca command"""
     if len(self.etf_holdings) > 0:
         self.queue = ca_controller.ComparisonAnalysisController(
             self.etf_holdings,
             self.queue).menu(custom_path_menu_above="/stocks/")
     else:
         console.print(
             "Load a ticker with major holdings to compare them on this menu\n"
         )
示例#7
0
def test_custom_reset(expected, similar):
    controller = ca_controller.ComparisonAnalysisController(
        similar=None,
        queue=None,
    )
    controller.similar = similar

    result = controller.custom_reset()

    assert result == expected
示例#8
0
 def call_ca(self, _):
     """Call the comparison analysis menu with selected tickers"""
     if self.tickers:
         self.queue = ca_controller.ComparisonAnalysisController(
             self.tickers,
             self.queue).menu(custom_path_menu_above="/stocks/")
     else:
         console.print(
             "No main ticker loaded to go into comparison analysis menu",
             "\n")
 def call_ca(self, _):
     """Call the comparison analysis menu with selected tickers"""
     if self.screen_tickers:
         self.queue = ca_controller.ComparisonAnalysisController(
             self.screen_tickers,
             self.queue).menu(custom_path_menu_above="/stocks/")
     else:
         console.print(
             "Some tickers must be screened first through one of the presets!\n"
         )
示例#10
0
def test_func_calling_get_similar_companies(tested_func, mocked_func,
                                            other_args, mocker):
    similar = ["MOCK_SIMILAR_" + str(i) for i in range(11)]
    user = "******"
    mock = mocker.Mock(return_value=(similar, user))
    target = "gamestonk_terminal.stocks.comparison_analysis." + mocked_func
    mocker.patch(target=target, new=mock)

    controller = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR"])
    getattr(controller, tested_func)(other_args=other_args)
    mock.assert_called_once()
示例#11
0
def test_call_func_no_parser(func, mocker):
    mocker.patch(
        "gamestonk_terminal.stocks.comparison_analysis.ca_controller.parse_known_args_and_warn",
        return_value=None,
    )
    controller = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"])

    func_result = getattr(controller, func)(other_args=list())
    assert func_result is None
    assert controller.queue == []
    getattr(ca_controller, "parse_known_args_and_warn").assert_called_once()
示例#12
0
def test_menu_with_queue(expected, mocker, queue):
    mocker.patch(
        target=("gamestonk_terminal.stocks.comparison_analysis.ca_controller."
                "ComparisonAnalysisController.switch"),
        return_value=["quit"],
    )
    result_menu = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"],
        queue=queue,
    ).menu()

    assert result_menu == expected
示例#13
0
def test_call_func(tested_func, mocked_func, other_args, called_with, mocker):
    if mocked_func:
        mock = mocker.Mock()
        mocker.patch(
            "gamestonk_terminal.stocks.comparison_analysis." + mocked_func,
            new=mock,
        )

        controller = ca_controller.ComparisonAnalysisController(
            similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"], )
        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)
        else:
            mock.assert_called_once()
    else:
        controller = ca_controller.ComparisonAnalysisController(
            similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"], )
        getattr(controller, tested_func)(other_args=other_args)
示例#14
0
def test_call_tsne(mocker):
    similar = ["MOCK_SIMILAR"]
    mock = mocker.Mock(return_value=["MOCK_SIMILAR", "MOCK_USER"])
    target = "gamestonk_terminal.stocks.comparison_analysis.yahoo_finance_model.get_sp500_comps_tsne"
    mocker.patch(target=target, new=mock)

    controller = ca_controller.ComparisonAnalysisController(similar=similar)
    controller.call_tsne(other_args=[
        "--learnrate=100",
        "--limit=5",
        "--no_plot",
    ])
    mock.assert_called_once_with(
        "MOCK_SIMILAR",
        lr=100,
        no_plot=True,
        num_tickers=5,
    )
示例#15
0
def test_menu_without_queue_sys_exit(mock_input, mocker):
    # DISABLE AUTO-COMPLETION
    mocker.patch.object(
        target=ca_controller.gtff,
        attribute="USE_PROMPT_TOOLKIT",
        new=False,
    )
    mocker.patch(
        target="gamestonk_terminal.stocks.comparison_analysis.ca_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.comparison_analysis.ca_controller."
            "ComparisonAnalysisController.switch"
        ),
        new=mock_switch,
    )

    result_menu = ca_controller.ComparisonAnalysisController(
        similar=["MOCK_SIMILAR_1", "MOCK_SIMILAR_2"],
        queue=None,
    ).menu()

    assert result_menu == []
示例#16
0
def test_print_help():
    controller = ca_controller.ComparisonAnalysisController()
    controller.print_help()
示例#17
0
def test_switch(an_input, expected_queue):
    controller = ca_controller.ComparisonAnalysisController()
    queue = controller.switch(an_input=an_input)

    assert queue == expected_queue