Files
OpenBB/tests/openbb_terminal/test_loggers.py
Henrique Joaquim 937d033160 Adds BaseModel and SystemModel (#4491)
* adding BaseModel

* initial version of the system model

* creating setup functions and removing constants from config_terminal

* removing log_supress const

* fix test

* merge

* system handler

* fix import

* centralized configs setup

* repr to use the BaseModel

* updating i18n dict location

* ignoring warning on wrong type-var

* ruff

* Update openbb_terminal/core/models/system_model.py

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>

* Update openbb_terminal/core/models/system_model.py

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>

* import literal

* loading env files before the plot backend is called

* fix tests/openbb_terminal/test_terminal_helper.py

* tests need to have i18n initialized

* fix seeking_alpha tests

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
2023-03-22 15:00:58 +00:00

107 lines
2.6 KiB
Python

from pathlib import Path
import pytest
from openbb_terminal import loggers
from openbb_terminal.core.log.generation.settings import (
AppSettings,
AWSSettings,
LogSettings,
Settings,
)
settings = Settings(
app_settings=AppSettings(
commit_hash="MOCK_COMMIT_HASH",
name="MOCK_COMMIT_HASH",
identifier="MOCK_COMMIT_HASH",
session_id="MOCK_SESSION_ID",
user_id="MOCK_USER_ID",
),
aws_settings=AWSSettings(
aws_access_key_id="MOCK_AWS_ACCESS_KEY_ID",
aws_secret_access_key="MOCK_AWS", # pragma: allowlist secret
),
log_settings=LogSettings(
directory=Path("."),
frequency="H",
handler_list="file",
rolling_clock=False,
verbosity=20,
),
)
def throw_os_error():
raise OSError("This is a test error")
def throw_os_error_30():
e = OSError()
e.errno = 30
raise e
def throw_generic():
raise Exception("This is a test error")
@pytest.mark.parametrize(
"to_mock", [None, throw_os_error, throw_os_error_30, throw_generic]
)
def test_get_app_id(to_mock, mocker):
if to_mock:
mocker.patch("openbb_terminal.loggers.get_log_dir", to_mock)
with pytest.raises(Exception):
value = loggers.get_app_id()
else:
value = loggers.get_app_id()
assert value
@pytest.mark.parametrize("git", [True, False])
def test_get_commit_hash(mocker, git):
mocker.patch("openbb_terminal.loggers.WITH_GIT", git)
value = loggers.get_commit_hash()
assert value
def test_get_commit_hash_obff(mocker):
mocker.patch(
"openbb_terminal.loggers.current_system.LOGGING_COMMIT_HASH",
"MOCKING_COMMIT_HASH",
)
value = loggers.get_commit_hash()
assert value
@pytest.mark.skip(reason="Change the state of the logger.")
def test_add_stdout_handler():
loggers.add_stdout_handler(settings)
@pytest.mark.skip(reason="Change the state of the logger.")
def test_add_stderr_handler():
loggers.add_stderr_handler(settings)
@pytest.mark.skip(reason="Change the state of the logger.")
def test_add_nopp_handler():
loggers.add_noop_handler(settings)
@pytest.mark.skip(reason="Change the state of the logger + lead to file generation.")
def test_add_file_handler():
loggers.add_file_handler(settings)
@pytest.mark.skip(reason="Change the state of the logger.")
def test_setup_handlers():
loggers.setup_handlers(settings)
@pytest.mark.skip(reason="Change the state of the logger.")
def test_setup_logging(mocker):
mocker.patch("openbb_terminal.loggers.setup_handlers")
loggers.setup_logging(settings)