Correction on tests

This commit is contained in:
Nicolas Papp 2022-04-24 17:37:09 -03:00
parent 0f943c482b
commit 086cc6be93
2 changed files with 14 additions and 6 deletions

View File

@ -511,9 +511,7 @@ def calculate_max_drawdown(trades: pd.DataFrame, *, date_col: str = 'close_date'
high_val = max_drawdown_df.loc[max_drawdown_df.iloc[:idxmin]
['high_value'].idxmax(), 'cumulative']
low_val = max_drawdown_df.loc[idxmin, 'cumulative']
max_drawdown_rel = 0.0
if starting_balance != 0:
max_drawdown_rel = max_drawdown_df.loc[idxmin, 'drawdown_relative']
max_drawdown_rel = max_drawdown_df.loc[idxmin, 'drawdown_relative']
return (
abs(min(max_drawdown_df['drawdown'])),

View File

@ -331,7 +331,13 @@ def test_generate_profit_graph(testdatadir):
trades = trades[trades['pair'].isin(pairs)]
fig = generate_profit_graph(pairs, data, trades, timeframe="5m", stake_currency='BTC')
fig = generate_profit_graph(
pairs,
data,
trades,
timeframe="5m",
stake_currency='BTC',
starting_balance=0)
assert isinstance(fig, go.Figure)
assert fig.layout.title.text == "Freqtrade Profit plot"
@ -340,7 +346,7 @@ def test_generate_profit_graph(testdatadir):
assert fig.layout.yaxis3.title.text == "Profit BTC"
figure = fig.layout.figure
assert len(figure.data) == 7
assert len(figure.data) == 8
avgclose = find_trace_in_fig_data(figure.data, "Avg close price")
assert isinstance(avgclose, go.Scatter)
@ -355,6 +361,9 @@ def test_generate_profit_graph(testdatadir):
underwater = find_trace_in_fig_data(figure.data, "Underwater Plot")
assert isinstance(underwater, go.Scatter)
underwater_relative = find_trace_in_fig_data(figure.data, "Underwater Plot (%)")
assert isinstance(underwater_relative, go.Scatter)
for pair in pairs:
profit_pair = find_trace_in_fig_data(figure.data, f"Profit {pair}")
assert isinstance(profit_pair, go.Scatter)
@ -362,7 +371,7 @@ def test_generate_profit_graph(testdatadir):
with pytest.raises(OperationalException, match=r"No trades found.*"):
# Pair cannot be empty - so it's an empty dataframe.
generate_profit_graph(pairs, data, trades.loc[trades['pair'].isnull()], timeframe="5m",
stake_currency='BTC')
stake_currency='BTC', starting_balance=0)
def test_start_plot_dataframe(mocker):
@ -444,6 +453,7 @@ def test_plot_profit(default_conf, mocker, testdatadir):
default_conf['datadir'] = testdatadir
default_conf['exportfilename'] = testdatadir / 'backtest-result_test_nofile.json'
default_conf['pairs'] = ['ETH/BTC', 'LTC/BTC']
default_conf['available_capital'] = 1000
profit_mock = MagicMock()
store_mock = MagicMock()