mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-06-06 12:44:05 +08:00
* Added common/helper tests * expanded bot testing * few changes * import fix * missed removing test config * column order fix * import fix * removed df2img add new deps * req * update readme * add dep for image export, fix * get rid of yahoo-fin, add image export lib * import issues in some machines fix * images dir fix * init fix * fix? * test * test * Fixed text handling * missed a tbl * Fixed tests * Fixed poetry * Fixed kaliedo * Fixed codecov * Fixed dependencies * Added fix * FIxed tests * Added image cleanup * Added tests * Fixed tests * Added test fix * Added conda * Updated bot path * refactor * poetry * update dict/ fix slack image upload * Update config_discordbot.py * Updated * Fixed tests * Skipped energy * fixes * black * fix * import * fix nan on smile * added env settings * add cmds_text dict, some chgs * merge bot test fixes * fix duplicate Co-authored-by: teh_coderer <me@tehcoderer.com> Co-authored-by: Colin Delahunty <colindelahunty@MacBook-Pro.local> Co-authored-by: Chavithra <chavithra@gmail.com>
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import functools
|
|
import io
|
|
import logging
|
|
import sys
|
|
from typing import Union
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def calc_change(current: Union[float, int], previous: Union[float, int]):
|
|
"""Calculates change between two different values"""
|
|
if current == previous:
|
|
return 0
|
|
try:
|
|
return ((current - previous) / previous) * 100.0
|
|
except ZeroDivisionError:
|
|
logging.exception("zero division")
|
|
return float("inf")
|
|
|
|
|
|
def check_print(assert_in: str = "", length: int = -1):
|
|
"""Captures output of print function and checks if the function contains a given string"""
|
|
|
|
def checker(func):
|
|
@functools.wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
capturedOutput = io.StringIO()
|
|
sys.stdout = capturedOutput
|
|
func(*args, **kwargs)
|
|
sys.stdout = sys.__stdout__
|
|
capt = capturedOutput.getvalue()
|
|
if assert_in:
|
|
assert assert_in in capt
|
|
return None
|
|
if length >= 0:
|
|
assert len(capt) > length
|
|
return capt
|
|
|
|
return wrapper
|
|
|
|
return checker
|