diff --git a/.terminal.py.swp b/.terminal.py.swp new file mode 100644 index 00000000000..5031ee29223 Binary files /dev/null and b/.terminal.py.swp differ diff --git a/gamestonk_terminal/jupyter/dashboards/shortdata.ipynb b/gamestonk_terminal/jupyter/dashboards/shortdata.ipynb index 1ca74f876ed..04e1791cfb2 100644 --- a/gamestonk_terminal/jupyter/dashboards/shortdata.ipynb +++ b/gamestonk_terminal/jupyter/dashboards/shortdata.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": 1, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -22,6 +25,15 @@ { "cell_type": "code", "execution_count": 47, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "class ShortDataDash:\n", @@ -164,43 +176,51 @@ " self.ticker_button,\n", " self.output2,\n", " ]" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "code", "execution_count": 48, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [], "source": [ "dash = ShortDataDash()\n", "app = widgets.VBox(\n", " dash.build_app(), layout=widgets.Layout(max_width=\"1024px\", margin=\"0 auto 0 auto\")\n", ")" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] }, { "cell_type": "code", "execution_count": 49, + "metadata": { + "collapsed": false, + "jupyter": { + "outputs_hidden": false + }, + "pycharm": { + "name": "#%%\n" + } + }, "outputs": [ { "data": { - "text/plain": "VBox(children=(HTML(value=\"\\n

Finra Short Data

\\n

This widget downloads the consolidated NMS short da…", "application/vnd.jupyter.widget-view+json": { + "model_id": "dcda08c8d643465fb862d01341d71370", "version_major": 2, - "version_minor": 0, - "model_id": "dcda08c8d643465fb862d01341d71370" - } + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(HTML(value=\"\\n

Finra Short Data

\\n

This widget downloads the consolidated NMS short da…" + ] }, "metadata": {}, "output_type": "display_data" @@ -208,34 +228,28 @@ ], "source": [ "display(app)" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "name": "#%%\n" - } - } + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" + "pygments_lexer": "ipython3", + "version": "3.8.12" } }, "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file + "nbformat_minor": 4 +} diff --git a/terminal.py b/terminal.py index eafe1ead4a5..4edeaa611dd 100644 --- a/terminal.py +++ b/terminal.py @@ -362,7 +362,60 @@ def run_scripts(path: str, test_mode: bool = False): terminal() +def main(debug: bool, test: bool, filtert: str, path: List[str]): + if test: + os.environ["DEBUG_MODE"] = "true" + + if "gst" in path[0]: + files = path + else: + folder = os.path.join(os.path.abspath(os.path.dirname(__file__)), path[0]) + files = [ + name + for name in os.listdir(folder) + if os.path.isfile(os.path.join(folder, name)) + and name.endswith(".gst") + and (filtert in f"{folder}/{name}") + ] + files.sort() + SUCCESSES = 0 + FAILURES = 0 + fails = {} + length = len(files) + i = 0 + console.print("[green]Gamestonk Terminal Integrated Tests:\n[/green]") + for file in files: + console.print(f"{file} {((i/length)*100):.1f}%") + try: + with suppress_stdout(): + run_scripts(f"{path[0]}/{file}", test_mode=True) + SUCCESSES += 1 + except Exception as e: + fails[f"{path[0]}{file}"] = e + FAILURES += 1 + i += 1 + if fails: + console.print("\n[red]Failures:[/red]\n") + for key, value in fails.items(): + console.print(f"{key}: {value}\n") + console.print( + f"Summary: [green]Successes: {SUCCESSES}[/green] [red]Failures: {FAILURES}[/red]" + ) + else: + if debug: + os.environ["DEBUG_MODE"] = "true" + if isinstance(path, list) and path[0].endswith(".gst"): + run_scripts(path[0]) + elif path: + argv_cmds = list([" ".join(path).replace(" /", "/home/")]) + argv_cmds = insert_start_slash(argv_cmds) if argv_cmds else argv_cmds + terminal(argv_cmds) + else: + terminal() + + if __name__ == "__main__": + parser = argparse.ArgumentParser( formatter_class=argparse.ArgumentDefaultsHelpFormatter, prog="terminal", @@ -397,7 +450,7 @@ if __name__ == "__main__": "-f", "--filter", help="Send a keyword to filter in file name", - dest="filter", + dest="filtert", default="", type=str, ) @@ -407,54 +460,4 @@ if __name__ == "__main__": ns_parser = parser.parse_args() if ns_parser: - if ns_parser.test: - os.environ["DEBUG_MODE"] = "true" - - if "gst" in ns_parser.path[0]: - files = ns_parser.path - else: - folder = os.path.join( - os.path.abspath(os.path.dirname(__file__)), ns_parser.path[0] - ) - files = [ - name - for name in os.listdir(folder) - if os.path.isfile(os.path.join(folder, name)) - and name.endswith(".gst") - and (ns_parser.filter in f"{folder}/{name}") - ] - files.sort() - SUCCESSES = 0 - FAILURES = 0 - fails = {} - length = len(files) - i = 0 - console.print("[green]Gamestonk Terminal Integrated Tests:\n[/green]") - for file in files: - console.print(f"{file} {((i/length)*100):.1f}%") - try: - with suppress_stdout(): - run_scripts(f"{ns_parser.path[0]}/{file}", test_mode=True) - SUCCESSES += 1 - except Exception as e: - fails[f"{ns_parser.path[0]}{file}"] = e - FAILURES += 1 - i += 1 - if fails: - console.print("\n[red]Failures:[/red]\n") - for key, value in fails.items(): - console.print(f"{key}: {value}\n") - console.print( - f"Summary: [green]Successes: {SUCCESSES}[/green] [red]Failures: {FAILURES}[/red]" - ) - else: - if ns_parser.debug: - os.environ["DEBUG_MODE"] = "true" - if isinstance(ns_parser.path, list) and ns_parser.path[0].endswith(".gst"): - run_scripts(ns_parser.path[0]) - elif ns_parser.path: - argv_cmds = list([" ".join(ns_parser.path).replace(" /", "/home/")]) - argv_cmds = insert_start_slash(argv_cmds) if argv_cmds else argv_cmds - terminal(argv_cmds) - else: - terminal() + main(ns_parser.debug, ns_parser.test, ns_parser.filtert, ns_parser.path) diff --git a/tests/.test_terminal.py.swp b/tests/.test_terminal.py.swp new file mode 100644 index 00000000000..28f1a787c94 Binary files /dev/null and b/tests/.test_terminal.py.swp differ diff --git a/tests/gamestonk_terminal/txt/test_menu/test_menu[False-False-None-path1].txt b/tests/gamestonk_terminal/txt/test_menu/test_menu[False-False-None-path1].txt new file mode 100644 index 00000000000..9e3d967f2a1 --- /dev/null +++ b/tests/gamestonk_terminal/txt/test_menu/test_menu[False-False-None-path1].txt @@ -0,0 +1,7 @@ + +(✨) /alternative/ $ covid +(✨) /alternative/covid/ $ country Australia +[cyan]Australia[/cyan] loaded + +(✨) /alternative/covid/ $ reset +resetting... diff --git a/tests/gamestonk_terminal/txt/test_menu/test_menu[False-True-alt_covid-path2].txt b/tests/gamestonk_terminal/txt/test_menu/test_menu[False-True-alt_covid-path2].txt new file mode 100644 index 00000000000..4b858482ae4 --- /dev/null +++ b/tests/gamestonk_terminal/txt/test_menu/test_menu[False-True-alt_covid-path2].txt @@ -0,0 +1,11 @@ +[green]Gamestonk Terminal Integrated Tests: +[/green] +test_alt_covid.gst 0.0% + +[red]Failures:[/red] + +scripts/test_alt_covid.gst: Can't overwrite existing cassette ('/Users/colindelahunty/Desktop/GamestonkTerminal/tests/gamestonk_terminal/cassettes/test_menu/test_menu[False-True-alt_covid-path2].yaml') in your current record mode ('none'). +No match for the request () was found. +No similar requests, that have not been played, found. + +Summary: [green]Successes: 0[/green] [red]Failures: 1[/red] diff --git a/tests/gamestonk_terminal/txt/test_menu/test_menu[True-False-None-None].txt b/tests/gamestonk_terminal/txt/test_menu/test_menu[True-False-None-None].txt new file mode 100644 index 00000000000..c98f4986ace --- /dev/null +++ b/tests/gamestonk_terminal/txt/test_menu/test_menu[True-False-None-None].txt @@ -0,0 +1,41 @@ + +Welcome to Gamestonk Terminal Beta + + +Multiple jobs queue (where each '/' denotes a new command). + E.g. '/stocks $ disc/ugs -n 3/../load tsla/candle' + +If you want to jump from crypto/ta to stocks you can use an absolute path that starts with a slash (/). + E.g. '/crypto/ta $ /stocks' + +The previous logic also holds for when launching the terminal. + E.g. '$ python terminal.py /stocks/disc/ugs -n 3/../load tsla/candle' + +The main commands you should be aware when navigating through the terminal are: + cls clear the screen + help / h / ? help menu + quit / q / .. quit this menu and go one menu above + exit exit the terminal + reset / r reset the terminal and reload configs from the current location + resources only available on main contexts (not sub-menus) + + about about us + update update terminal automatically + tz set different timezone +> settings set feature flags and style charts +> keys set API keys and check their validity + +Timezone: America/New_York + +> stocks +> crypto +> etf +> economy +> forex +> funds +> alternative +> portfolio +> jupyter +> custom + +(✨) / $ \ No newline at end of file diff --git a/tests/test_terminal.py b/tests/test_terminal.py index 857e9f54548..54fb7e6b4f7 100644 --- a/tests/test_terminal.py +++ b/tests/test_terminal.py @@ -1,10 +1,9 @@ +from contextlib import contextmanager import pytest import terminal -pytest.skip(allow_module_level=True) - - +@pytest.mark.skip @pytest.mark.block_network @pytest.mark.vcr(record_mode="none") @pytest.mark.record_stdout @@ -18,6 +17,7 @@ def test_terminal_quick_exit(mocker, monkeypatch): terminal.terminal() +@pytest.mark.skip @pytest.mark.vcr(record_mode="none") @pytest.mark.record_stdout def test_terminal_quit(mocker, monkeypatch): @@ -35,3 +35,24 @@ def test_terminal_quit(mocker, monkeypatch): terminal.terminal() spy_print_goodbye.assert_called_once() + + +@contextmanager +def no_suppress(): + yield + + +@pytest.mark.vcr(record_mode="none") +@pytest.mark.record_stdout +@pytest.mark.parametrize( + "debug, test, filtert, path", + [ + (True, False, None, None), + (False, False, None, ["scripts/test_alt_covid.gst"]), + (False, True, "alt_covid", ["scripts/"]), + ], +) +def test_menu(mocker, debug, test, filtert, path): + mocker.patch(target="terminal.terminal") + mocker.patch(target="terminal.suppress_stdout", side_effect=no_suppress) + terminal.main(debug, test, filtert, path) diff --git a/tests/txt/test_terminal/test_menu[False-False-None-path1].txt b/tests/txt/test_terminal/test_menu[False-False-None-path1].txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/txt/test_terminal/test_menu[False-True-alt_covid-path2].txt b/tests/txt/test_terminal/test_menu[False-True-alt_covid-path2].txt new file mode 100644 index 00000000000..8bd0f76ce0a --- /dev/null +++ b/tests/txt/test_terminal/test_menu[False-True-alt_covid-path2].txt @@ -0,0 +1,4 @@ +[green]Gamestonk Terminal Integrated Tests: +[/green] +test_alt_covid.gst 0.0% +Summary: [green]Successes: 1[/green] [red]Failures: 0[/red] diff --git a/tests/txt/test_terminal/test_menu[True-False-None-None].txt b/tests/txt/test_terminal/test_menu[True-False-None-None].txt new file mode 100644 index 00000000000..e69de29bb2d