Files
OpenBB/tests/test_terminal.py
Colin Delahunty dfcd515500 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>
2022-02-22 19:54:29 -05:00

59 lines
1.7 KiB
Python

from contextlib import contextmanager
import pytest
import terminal
@pytest.mark.skip
@pytest.mark.block_network
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_terminal_quick_exit(mocker, monkeypatch):
monkeypatch.setattr(terminal.gtff, "ENABLE_QUICK_EXIT", True)
monkeypatch.setattr(terminal.gtff, "USE_ION", False)
monkeypatch.setattr(terminal.gtff, "USE_PROMPT_TOOLKIT", True)
mocker.patch("sys.stdin")
terminal.terminal()
@pytest.mark.skip
@pytest.mark.vcr(record_mode="none")
@pytest.mark.record_stdout
def test_terminal_quit(mocker, monkeypatch):
monkeypatch.setattr(terminal.gtff, "ENABLE_QUICK_EXIT", False)
monkeypatch.setattr(terminal.gtff, "USE_ION", False)
monkeypatch.setattr(terminal.gtff, "USE_PROMPT_TOOLKIT", True)
mocker.patch("sys.stdin")
mocker.patch("builtins.input", return_value="e")
mocker.patch("terminal.session")
mocker.patch("terminal.session.prompt", return_value="e")
mocker.patch("terminal.print_goodbye")
spy_print_goodbye = mocker.spy(terminal, "print_goodbye")
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)