def call_spectrum(self, other_args: List[str]):
        """Process spectrum command"""
        parser = argparse.ArgumentParser(
            add_help=False,
            formatter_class=argparse.ArgumentDefaultsHelpFormatter,
            prog="spectrum",
            description="""
                View group (sectors, industry or country) spectrum data. [Source: Finviz]
            """,
        )
        parser.add_argument(
            "-g",
            "--group",
            type=str,
            default="sector",
            nargs="+",
            dest="group",
            help="Data group (sector, industry or country)",
        )
        if other_args and "-" not in other_args[0][0]:
            other_args.insert(0, "-g")

        ns_parser = parse_known_args_and_warn(
            parser, other_args, export_allowed=EXPORT_ONLY_FIGURES_ALLOWED)
        if ns_parser:
            group = (" ".join(ns_parser.group) if isinstance(
                ns_parser.group, list) else ns_parser.group)
            finviz_view.display_spectrum(s_group=self.d_GROUPS[group])

            # Due to Finviz implementation of Spectrum, we delete the generated spectrum figure
            # after saving it and displaying it to the user
            os.remove(self.d_GROUPS[group] + ".jpg")
Пример #2
0
def test_display_spectrum(mocker):
    # MOCK GET_SPECTRUM_DATA
    mocker.patch(
        target=
        "gamestonk_terminal.economy.finviz_view.finviz_model.get_spectrum_data"
    )

    # MOCK EXPORT_DATA
    mocker.patch(target="gamestonk_terminal.economy.finviz_view.export_data")

    # MOCK OPEN
    mock_image = mocker.Mock()
    mocker.patch(
        target="gamestonk_terminal.economy.finviz_view.Image",
        new=mock_image,
    )

    finviz_view.display_spectrum(
        s_group="Sector",
        export="",
    )

    mock_image.open().show.assert_called_once()