Rename text_table generation

This commit is contained in:
Matthias 2020-06-07 11:35:02 +02:00
parent 499c6772d1
commit 070913f327
3 changed files with 15 additions and 16 deletions

View File

@ -226,7 +226,7 @@ def generate_backtest_stats(config: Dict, btdata: Dict[str, DataFrame],
# Start output section
###
def generate_text_table(pair_results: List[Dict[str, Any]], stake_currency: str) -> str:
def text_table_bt_results(pair_results: List[Dict[str, Any]], stake_currency: str) -> str:
"""
Generates and returns a text table for the given backtest data and the results dataframe
:param pair_results: List of Dictionaries - one entry per pair + final TOTAL row
@ -298,7 +298,7 @@ def show_backtest_results(config: Dict, backtest_stats: Dict):
# Print results
print(f"Result for strategy {strategy}")
table = generate_text_table(results['results_per_pair'], stake_currency=stake_currency)
table = text_table_bt_results(results['results_per_pair'], stake_currency=stake_currency)
if isinstance(table, str):
print(' BACKTESTING REPORT '.center(len(table.splitlines()[0]), '='))
print(table)
@ -309,7 +309,7 @@ def show_backtest_results(config: Dict, backtest_stats: Dict):
print(' SELL REASON STATS '.center(len(table.splitlines()[0]), '='))
print(table)
table = generate_text_table(results['left_open_trades'], stake_currency=stake_currency)
table = text_table_bt_results(results['left_open_trades'], stake_currency=stake_currency)
if isinstance(table, str):
print(' LEFT OPEN TRADES REPORT '.center(len(table.splitlines()[0]), '='))
print(table)

View File

@ -659,17 +659,17 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir):
mocker.patch('freqtrade.pairlist.pairlistmanager.PairListManager.whitelist',
PropertyMock(return_value=['UNITTEST/BTC']))
mocker.patch('freqtrade.optimize.backtesting.Backtesting.backtest', backtestmock)
gen_table_mock = MagicMock()
text_table_mock = MagicMock()
sell_reason_mock = MagicMock()
gen_strattable_mock = MagicMock()
gen_strat_summary = MagicMock()
strattable_mock = MagicMock()
strat_summary = MagicMock()
mocker.patch.multiple('freqtrade.optimize.optimize_reports',
generate_text_table=gen_table_mock,
text_table_strategy=gen_strattable_mock,
text_table_bt_results=text_table_mock,
text_table_strategy=strattable_mock,
generate_pair_metrics=MagicMock(),
generate_sell_reason_stats=sell_reason_mock,
generate_strategy_metrics=gen_strat_summary,
generate_strategy_metrics=strat_summary,
)
patched_configuration_load_config_file(mocker, default_conf)
@ -690,10 +690,10 @@ def test_backtest_start_multi_strat(default_conf, mocker, caplog, testdatadir):
start_backtesting(args)
# 2 backtests, 4 tables
assert backtestmock.call_count == 2
assert gen_table_mock.call_count == 4
assert gen_strattable_mock.call_count == 1
assert text_table_mock.call_count == 4
assert strattable_mock.call_count == 1
assert sell_reason_mock.call_count == 2
assert gen_strat_summary.call_count == 1
assert strat_summary.call_count == 1
# check the logs, that will contain the backtest result
exists = [

View File

@ -7,13 +7,13 @@ from arrow import Arrow
from freqtrade.edge import PairInfo
from freqtrade.optimize.optimize_reports import (
generate_pair_metrics, generate_edge_table, generate_sell_reason_stats,
generate_text_table, text_table_sell_reason, generate_strategy_metrics,
text_table_bt_results, text_table_sell_reason, generate_strategy_metrics,
text_table_strategy, store_backtest_result)
from freqtrade.strategy.interface import SellType
from tests.conftest import patch_exchange
def test_generate_text_table(default_conf, mocker):
def test_text_table_bt_results(default_conf, mocker):
results = pd.DataFrame(
{
@ -40,8 +40,7 @@ def test_generate_text_table(default_conf, mocker):
pair_results = generate_pair_metrics(data={'ETH/BTC': {}}, stake_currency='BTC',
max_open_trades=2, results=results)
assert generate_text_table(pair_results,
stake_currency='BTC') == result_str
assert text_table_bt_results(pair_results, stake_currency='BTC') == result_str
def test_generate_pair_metrics(default_conf, mocker):