Refactored menu (#1354)

* Refactored menu

* Updated test

* Changes

* Added Lucas change

* Refactored

* Test fixes

* Fixed tests

Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
This commit is contained in:
Colin Delahunty
2022-02-22 19:54:29 -05:00
committed by GitHub
parent 4d2e0252b3
commit dfcd515500
11 changed files with 188 additions and 87 deletions

BIN
.terminal.py.swp vendored Normal file

Binary file not shown.

View File

@@ -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<h2>Finra Short Data</h2>\\n<p>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<h2>Finra Short Data</h2>\\n<p>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
}
"nbformat_minor": 4
}

View File

@@ -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)

BIN
tests/.test_terminal.py.swp vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,7 @@
(✨) /alternative/ $ covid
(✨) /alternative/covid/ $ country Australia
[cyan]Australia[/cyan] loaded
(✨) /alternative/covid/ $ reset
resetting...

View File

@@ -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 (<Request (GET) https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv>) was found.
No similar requests, that have not been played, found.
Summary: [green]Successes: 0[/green] [red]Failures: 1[/red]

View File

@@ -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
(✨) / $

View File

@@ -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)

View File

@@ -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]