From 0eb109f8f7a01d8962f76cd89a111c9aa8ab3a7a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 16 Jun 2019 19:53:48 +0200 Subject: [PATCH] Improve some tests --- freqtrade/arguments.py | 8 ++++---- freqtrade/tests/test_plotting.py | 23 +++++++++++++++++++++-- scripts/plot_dataframe.py | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/freqtrade/arguments.py b/freqtrade/arguments.py index cef38784d..3f21709c9 100644 --- a/freqtrade/arguments.py +++ b/freqtrade/arguments.py @@ -528,8 +528,8 @@ class Arguments(object): ) self.parser.add_argument( '--indicators1', - help='Set indicators from your strategy you want in the first row of the graph. Separate ' - 'them with a comma. E.g: ema3,ema5 (default: %(default)s)', + help='Set indicators from your strategy you want in the first row of the graph. ' + 'Separate them with a comma. E.g: ema3,ema5 (default: %(default)s)', type=str, default='sma,ema3,ema5', dest='indicators1', @@ -537,8 +537,8 @@ class Arguments(object): self.parser.add_argument( '--indicators2', - help='Set indicators from your strategy you want in the third row of the graph. Separate ' - 'them with a comma. E.g: macd,fastd,fastk (default: %(default)s)', + help='Set indicators from your strategy you want in the third row of the graph. ' + 'Separate them with a comma. E.g: macd,fastd,fastk (default: %(default)s)', type=str, default='macd,macdsignal', dest='indicators2', diff --git a/freqtrade/tests/test_plotting.py b/freqtrade/tests/test_plotting.py index b1dad5d5c..15ab698d8 100644 --- a/freqtrade/tests/test_plotting.py +++ b/freqtrade/tests/test_plotting.py @@ -5,8 +5,9 @@ from plotly import tools import plotly.graph_objs as go from copy import deepcopy -from freqtrade.arguments import Arguments, TimeRange +from freqtrade.arguments import TimeRange from freqtrade.data import history +from freqtrade.data.btanalysis import load_backtest_data from freqtrade.plot.plotting import (generate_graph, generate_plot_file, generate_row, plot_trades) from freqtrade.strategy.default_strategy import DefaultStrategy @@ -71,8 +72,26 @@ def test_plot_trades(): # nothing happens when no trades are available fig = plot_trades(fig1, None) assert fig == fig1 + pair = "ADA/BTC" + filename = history.make_testdata_path(None) / "backtest-result_test.json" + trades = load_backtest_data(filename) + trades = trades.loc[trades['pair'] == pair] - # TODO: implement tests that do something + fig = plot_trades(fig, trades) + figure = fig1.layout.figure + + # Check buys - color, should be in first graph, ... + trade_buy = find_trace_in_fig_data(figure.data, "trade_buy") + assert isinstance(trade_buy, go.Scatter) + assert trade_buy.yaxis == 'y' + assert len(trades) == len(trade_buy.x) + assert trade_buy.marker.color == 'green' + + trade_sell = find_trace_in_fig_data(figure.data, "trade_sell") + assert isinstance(trade_sell, go.Scatter) + assert trade_sell.yaxis == 'y' + assert len(trades) == len(trade_sell.x) + assert trade_sell.marker.color == 'red' def test_generate_graph_no_signals_no_trades(default_conf, mocker, caplog): diff --git a/scripts/plot_dataframe.py b/scripts/plot_dataframe.py index e54a78124..54ce199f4 100755 --- a/scripts/plot_dataframe.py +++ b/scripts/plot_dataframe.py @@ -141,7 +141,7 @@ def analyse_and_plot_pairs(config: Dict[str, Any]): logger.info('End of ploting process %s plots generated', pair_counter) -def plot_parse_args(args: List[str]) -> Namespace: +def plot_parse_args(args: List[str]) -> Dict[str, Any]: """ Parse args passed to the script :param args: Cli arguments