From dfcd5155005e3220bcac3db618bfb143101e17e5 Mon Sep 17 00:00:00 2001 From: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Date: Tue, 22 Feb 2022 19:54:29 -0500 Subject: [PATCH] Refactored menu (#1354) * Refactored menu * Updated test * Changes * Added Lucas change * Refactored * Test fixes * Fixed tests Co-authored-by: didierlopes.eth --- .terminal.py.swp | Bin 0 -> 16384 bytes .../jupyter/dashboards/shortdata.ipynb | 78 +++++++------ terminal.py | 107 +++++++++--------- tests/.test_terminal.py.swp | Bin 0 -> 12288 bytes .../test_menu[False-False-None-path1].txt | 7 ++ .../test_menu[False-True-alt_covid-path2].txt | 11 ++ .../test_menu[True-False-None-None].txt | 41 +++++++ tests/test_terminal.py | 27 ++++- .../test_menu[False-False-None-path1].txt | 0 .../test_menu[False-True-alt_covid-path2].txt | 4 + .../test_menu[True-False-None-None].txt | 0 11 files changed, 188 insertions(+), 87 deletions(-) create mode 100644 .terminal.py.swp create mode 100644 tests/.test_terminal.py.swp create mode 100644 tests/gamestonk_terminal/txt/test_menu/test_menu[False-False-None-path1].txt create mode 100644 tests/gamestonk_terminal/txt/test_menu/test_menu[False-True-alt_covid-path2].txt create mode 100644 tests/gamestonk_terminal/txt/test_menu/test_menu[True-False-None-None].txt create mode 100644 tests/txt/test_terminal/test_menu[False-False-None-path1].txt create mode 100644 tests/txt/test_terminal/test_menu[False-True-alt_covid-path2].txt create mode 100644 tests/txt/test_terminal/test_menu[True-False-None-None].txt diff --git a/.terminal.py.swp b/.terminal.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..5031ee292236c483ad17498084628a594c76c8cd GIT binary patch literal 16384 zcmeI2ON<;x8OMtR+W}${Vkrj@`RXtEQ&AW~RJ7 zUG1*wUC%}i5&_ID7MEPe0VU!RiHC$p#1$bP5k!f?2@YI%g-ZlT;lkrzkDlpWc}>KD z1FDvOJ6&IWU5|f#^_bc2KlqumEA)}*A%g2(LgbGQ_4j{v`Htt_A|#c$C^DY2QC;YX zak%x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5t%IaFOcHzRgC(f?5g{n(lb?2f4`;5>@(vo}HHVpJK;z3t+s%6z4 z_UTjZ5HKC8ouV5RnuyrZee@CQ#CEj9=mux?#M&8TW2{|zebyScdHXFL!qZM`i*B3k zPTe;6O}=g7deBZ{toXIIVR{y58{Lx7w)g`;+vH}ow=AEzaCZ6hrDWyw`OBBkub%Br zt5XOXcSf-tYPRUM&FuT_wB04!2Dh<#OH<+Ug_V^P=TEshZKW8$HUA1O#jyHN!j8d| zGGl9RXyY>T=$>SX&yr?92^Qs{oigSID{zDp%sFf8CP{%;f0G20?FdF0ZxL$~*vf3u zOIpeW9PK6xW!=w3ime&DMW*J(*yz20?O%zEFW?2@oNw}+5I5C?O6*SUlu~tx-9f2D z=?qUeqZ1)%_8n(zJ>(Xup_EyF!d>nb&oTRXf)|w)8+v13N?n)E!77b|**vi)fMN4W z^R$+zsm`u|5XAL^c5x;*XNFrmVRr7u&Cl39eVxi`=8l#nUhzhnikCS{`Of2`YyRy{ zl`{{V{6w{P56#k!1qV|qoi?PqSBsmL`cq}%PnC)eu^#R9P=r%3PLhd@KkQpx!<|vL z=fjmqM@ecAYR!{KnLW%sQeqrRognb?4WT2y+?#dM*RyNUM{xTLvqHHt^rSSW3~x8v z%G4)k_{LC;n>4G2=neKa@7oNPPnu(MF8WQbRLz~5;ER{C=e6~3Iqj$0zrYGKv3X+t$_LE&s^poG~Gfa_7{XI%6PvX&eNFzKkDmt RdLYbyD0i65{~_kczX3P$0H6Q> literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..28f1a787c947ac6e0a5c2efd56d577f47ab1a840 GIT binary patch literal 12288 zcmeI2&2QX97>B1h@zqk%8zzI4r6@C8 zd}D3hIqNSmTqha(^zNzQZ`W7mKK`AtP^GbqL>lZA(oV_>2VW~?Ju|-^gcp@c<}bwB zPgNMC`)l8BcewDXFo{+9!sQ?n#wwW%gwA3aqze}JruyWze&*+gM6iD(x+eoME>s$IF17v^^txk_!8U!x50ZL1J}VO=z|T=0Vlv8PcilbxCg!f33vr8fkp5q z=6N4{0LnSP59lHTWPl8i0Wv@a$iRO#;NY5_Tg-x3dXX3w<1QW=+jT~9ic4Zihu; zRE5MdAq#IBL)SSZ)@3#w;YPQLx{Tbr6r@IUoq;a!=?1Cgq1ufj1i9^+P{%n=a=JG< z54WfrZYYU{dv!}keAbOWHn!b*I#8=|*+o6Tb`_ZW_j7Q&?0h~c2l2B&Cs3|&{M73B zmhjpoT7*hRwexn-Zm7MwI8%}6xe^gTD62-F#3GFWb>qUttE>Fl*4oMyzWQc0blt^lmo|&Y-zj1{+pZZ7PS-OlQ|!Uq z{udeCYHyM_uamSH+i!j}iPuh@$HMz`$q&>XCS2TnH1dZyL!WRd?7K=Q?RBl!CC+lC c?d+Yv>icO1un~5mQ@?Q1c<9un`(8nR0hsZa4FCWD literal 0 HcmV?d00001 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