Skip to content

Commit

Permalink
Fix ENABLE_RICH bug & fix test not catching the bug (OpenBB-finance#1448
Browse files Browse the repository at this point in the history
)

* Fix rich bug & fix tests not catching the bug

* Remove feature_flags diff

* Remove enable_rich and enable_rich_panel from ff

* Add back enable_rich_panel

* Setting default value back to True

* Disable rich when running tests

* Remove COLOR

* Fix tests

* Rewrite tests

* Remove default cassette

* Rewrite tests

Co-authored-by: Theodore Aptekarev <[email protected]>
  • Loading branch information
minhhoang1023 and piiq authored Mar 14, 2022
1 parent b200edf commit 0127c37
Show file tree
Hide file tree
Showing 36 changed files with 8,274 additions and 7,703 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pandas as pd
from matplotlib import pyplot as plt

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.config_terminal import theme
from gamestonk_terminal.common.behavioural_analysis import finbrain_model
from gamestonk_terminal.config_plot import PLOT_DPI
Expand All @@ -20,6 +19,8 @@
print_rich_table,
)
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -118,7 +119,7 @@ def display_sentiment_analysis(

df_sentiment.sort_index(ascending=True, inplace=True)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
color_df = df_sentiment["Sentiment Analysis"].apply(
lambda_sentiment_coloring, last_val=0
)
Expand Down
4 changes: 2 additions & 2 deletions gamestonk_terminal/common/prediction_techniques/arima_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import matplotlib.pyplot as plt
import pandas as pd

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.common.prediction_techniques import arima_model
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
print_prediction_kpis,
Expand All @@ -26,6 +25,7 @@
print_rich_table,
)
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -283,7 +283,7 @@ def display_arima(
df_pred = df_pred.to_frame()
df_pred["Real"] = df_future.values

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_pred["Real"] = df_pred["Real"].astype(float)
df_pred["Prediction"] = df_pred["Prediction"].astype(float)
df_pred["Dif"] = 100 * (df_pred.Prediction - df_pred.Real) / df_pred.Real
Expand Down
4 changes: 2 additions & 2 deletions gamestonk_terminal/common/prediction_techniques/ets_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import pandas as pd

from gamestonk_terminal.config_terminal import theme
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.common.prediction_techniques import ets_model
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
lambda_price_prediction_backtesting_color,
Expand All @@ -28,6 +27,7 @@
plot_autoscale,
)
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -291,7 +291,7 @@ def display_exponential_smoothing(
df_pred = df_pred.to_frame()
df_pred["Real"] = df_future

if gtff.USE_COLOR:
if rich_config.USE_COLOR:

patch_pandas_text_adjustment()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
print_rich_table,
)
from gamestonk_terminal import config_neural_network_models as cfg
from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.config_terminal import theme
from gamestonk_terminal.config_plot import PLOT_DPI
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -559,7 +559,7 @@ def lambda_price_prediction_color(val: float, last_val: float) -> str:
def print_pretty_prediction(df_pred: pd.DataFrame, last_price: float):
"""Print predictions"""
console.print("")
if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_pred = pd.DataFrame(df_pred)
df_pred.columns = ["pred"]
df_pred["pred"] = df_pred["pred"].apply(
Expand Down Expand Up @@ -588,7 +588,7 @@ def print_pretty_prediction(df_pred: pd.DataFrame, last_price: float):


def print_pretty_prediction_nn(df_pred: pd.DataFrame, last_price: float):
if gtff.USE_COLOR:
if rich_config.USE_COLOR:
console.print(f"Actual price: [yellow]{last_price:.2f} $[/yellow]\n")
console.print("Prediction:")
console.print(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pandas as pd
from pandas.plotting import register_matplotlib_converters

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.common.prediction_techniques import regression_model
from gamestonk_terminal.common.prediction_techniques.pred_helper import (
lambda_price_prediction_backtesting_color,
Expand All @@ -26,6 +25,7 @@
plot_autoscale,
)
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -246,7 +246,7 @@ def display_regression(
df_pred = df_pred.to_frame()
df_pred["Real"] = df_future

if gtff.USE_COLOR:
if rich_config.USE_COLOR:

patch_pandas_text_adjustment()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import pandas as pd

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.common.behavioural_analysis.finbrain_model import get_sentiment
from gamestonk_terminal.common.behavioural_analysis.finbrain_view import (
plot_sentiment,
Expand All @@ -15,6 +14,7 @@
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import export_data
from gamestonk_terminal.rich_config import console
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -57,7 +57,7 @@ def display_crypto_sentiment_analysis(coin: str, export: str) -> None:
plot_sentiment(df_sentiment, coin)
df_sentiment.sort_index(ascending=True, inplace=True)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
console.print(
df_sentiment["Sentiment Analysis"]
.apply(lambda_sentiment_coloring, last_val=0)
Expand Down
6 changes: 0 additions & 6 deletions gamestonk_terminal/feature_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# Use clear console after each command
USE_CLEAR_AFTER_CMD = strtobool(os.getenv("GTFF_USE_CLEAR_AFTER_CMD", "False"))

# Use coloring features
USE_COLOR = strtobool(os.getenv("GTFF_USE_COLOR", "True"))

# Select console flair (choose from the list in helper_funcs.py)
USE_FLAIR = os.getenv("GTFF_USE_FLAIR") or ":stars"

Expand Down Expand Up @@ -52,9 +49,6 @@
# Remember contexts during session
REMEMBER_CONTEXTS = strtobool(os.getenv("GTFF_REMEMBER_CONTEXTS", "True"))

# Use the colorful rich terminal
ENABLE_RICH = strtobool(os.getenv("GTFF_ENABLE_RICH", "True"))

# Use the colorful rich terminal
ENABLE_RICH_PANEL = strtobool(os.getenv("GTFF_ENABLE_RICH_PANEL", "True"))

Expand Down
12 changes: 6 additions & 6 deletions gamestonk_terminal/rich_config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Rich Module"""
__docformat__ = "numpy"

import os
from rich import panel
from rich.console import Console, Theme
from gamestonk_terminal import config_terminal as cfg
from gamestonk_terminal import feature_flags as gtff


# https://rich.readthedocs.io/en/stable/appendix/colors.html#appendix-colors
# https://rich.readthedocs.io/en/latest/highlighting.html#custom-highlighters

Expand All @@ -26,6 +28,8 @@
"[/help]",
]

USE_COLOR = True


def no_panel(renderable, *args, **kwargs): # pylint: disable=unused-argument
return renderable
Expand All @@ -49,7 +53,7 @@ def filter_rich_tags(text):

def print(self, *args, **kwargs):
if kwargs and "text" in list(kwargs) and "menu" in list(kwargs):
if gtff.ENABLE_RICH:
if not os.getenv("TEST_MODE"):
if gtff.ENABLE_RICH_PANEL:
self.console.print(
panel.Panel(
Expand All @@ -64,14 +68,10 @@ def print(self, *args, **kwargs):
else:
print(self.filter_rich_tags(kwargs["text"]))
else:
if gtff.ENABLE_RICH:
if not os.getenv("TEST_MODE"):
self.console.print(*args, **kwargs)
else:
print(*args, **kwargs)


console = ConsoleAndPanel()


def disable_rich():
gtff.ENABLE_RICH = False
18 changes: 0 additions & 18 deletions gamestonk_terminal/settings_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ def print_help(self):
help_text += (
f" [{color}]cls clear console after each command[/{color}]\n"
)
color = "green" if gtff.USE_COLOR else "red"
help_text += f" [{color}]color use coloring features[/{color}]\n"
color = "green" if gtff.USE_PROMPT_TOOLKIT else "red"
help_text += f" [{color}]promptkit enable prompt toolkit (autocomplete and history)[/{color}]\n"
color = "green" if gtff.ENABLE_PREDICT else "red"
Expand All @@ -95,8 +93,6 @@ def print_help(self):
help_text += f" [{color}]exithelp automatically print help when quitting menu[/{color}]\n"
color = "green" if gtff.REMEMBER_CONTEXTS else "red"
help_text += f" [{color}]rcontext remember contexts loaded params during session[/{color}]\n"
color = "green" if gtff.ENABLE_RICH else "red"
help_text += f" [{color}]rich colorful rich terminal[/{color}]\n"
color = "green" if gtff.ENABLE_RICH_PANEL else "red"
help_text += (
f" [{color}]richpanel colorful rich terminal panel[/{color}]\n"
Expand Down Expand Up @@ -160,13 +156,6 @@ def call_cls(self, _):
)
console.print("")

@log_start_end(log=logger)
def call_color(self, _):
"""Process color command"""
gtff.USE_COLOR = not gtff.USE_COLOR
dotenv.set_key(self.env_file, "GTFF_USE_COLOR", str(gtff.USE_COLOR))
console.print("")

@log_start_end(log=logger)
def call_promptkit(self, _):
"""Process promptkit command"""
Expand Down Expand Up @@ -226,13 +215,6 @@ def call_dt(self, _):
dotenv.set_key(self.env_file, "GTFF_USE_DATETIME", str(gtff.USE_DATETIME))
console.print("")

@log_start_end(log=logger)
def call_rich(self, _):
"""Process rich command"""
gtff.ENABLE_RICH = not gtff.ENABLE_RICH
dotenv.set_key(self.env_file, "GTFF_ENABLE_RICH", str(gtff.ENABLE_RICH))
console.print("")

@log_start_end(log=logger)
def call_richpanel(self, _):
"""Process richpanel command"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
from typing import List

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import (
export_data,
Expand All @@ -15,6 +14,7 @@
)
from gamestonk_terminal.rich_config import console
from gamestonk_terminal.stocks.comparison_analysis import marketwatch_model
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -50,7 +50,7 @@ def display_income_comparison(
df_financials_compared,
)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_financials_compared = df_financials_compared.applymap(
lambda_financials_colored_values
)
Expand Down Expand Up @@ -99,7 +99,7 @@ def display_balance_comparison(
df_financials_compared,
)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_financials_compared = df_financials_compared.applymap(
lambda_financials_colored_values
)
Expand Down Expand Up @@ -151,7 +151,7 @@ def display_cashflow_comparison(
df_financials_compared,
)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_financials_compared = df_financials_compared.applymap(
lambda_financials_colored_values
)
Expand Down
4 changes: 2 additions & 2 deletions gamestonk_terminal/stocks/discovery/ark_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import logging
import os

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import export_data, print_rich_table
from gamestonk_terminal.rich_config import console
from gamestonk_terminal.stocks.discovery import ark_model
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,7 +74,7 @@ def ark_orders_view(

if sort_col:
df_orders = df_orders.sort_values(by=sort_col, ascending=ascending)
if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_orders["direction"] = df_orders["direction"].apply(
lambda_direction_color_red_green
)
Expand Down
4 changes: 2 additions & 2 deletions gamestonk_terminal/stocks/discovery/fidelity_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import pandas as pd

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import export_data, print_rich_table
from gamestonk_terminal.rich_config import console
from gamestonk_terminal.stocks.discovery import fidelity_model
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -79,7 +79,7 @@ def orders_view(num: int, export: str):

pd.set_option("display.max_colwidth", None)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df_orders["Buy / Sell Ratio"] = df_orders["Buy / Sell Ratio"].apply(
lambda_buy_sell_ratio_color_red_green
)
Expand Down
4 changes: 2 additions & 2 deletions gamestonk_terminal/stocks/due_diligence/finviz_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import os
from typing import Any, List

from gamestonk_terminal import feature_flags as gtff
from gamestonk_terminal.decorators import log_start_end
from gamestonk_terminal.helper_funcs import export_data, print_rich_table
from gamestonk_terminal.rich_config import console
from gamestonk_terminal.stocks.due_diligence import finviz_model
from gamestonk_terminal import rich_config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,7 +74,7 @@ def analyst(ticker: str, export: str = ""):
"""
df = finviz_model.get_analyst_data(ticker)

if gtff.USE_COLOR:
if rich_config.USE_COLOR:
df["category"] = df["category"].apply(lambda_category_color_red_green)

print_rich_table(
Expand Down
Loading

0 comments on commit 0127c37

Please sign in to comment.