Skip to content

Commit

Permalink
Add test for analyse_and_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Aug 24, 2019
1 parent 99b2be9 commit 29076ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion freqtrade/plot/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,4 @@ def analyse_and_plot_pairs(config: Dict[str, Any]):
store_plot_file(fig, filename=generate_plot_filename(pair, config['ticker_interval']),
directory=config['user_data_dir'] / "plot")

logger.info('End of ploting process %s plots generated', pair_counter)
logger.info('End of plotting process. %s plots generated', pair_counter)
29 changes: 29 additions & 0 deletions freqtrade/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from freqtrade.data.btanalysis import create_cum_profit, load_backtest_data
from freqtrade.plot.plot_utils import start_plot_dataframe
from freqtrade.plot.plotting import (add_indicators, add_profit,
analyse_and_plot_pairs,
generate_candlestick_graph,
generate_plot_filename,
generate_profit_graph, init_plotscript,
Expand Down Expand Up @@ -286,3 +287,31 @@ def test_start_plot_dataframe(mocker):
called_config = aup.call_args_list[0][0][0]
assert "pairs" in called_config
assert called_config['pairs'] == ["ETH/BTC"]


def test_analyse_and_plot_pairs(default_conf, mocker, caplog):
default_conf['trade_source'] = 'file'
default_conf["datadir"] = history.make_testdata_path(None)
default_conf['exportfilename'] = str(
history.make_testdata_path(None) / "backtest-result_test.json")
default_conf['indicators1'] = "sma5,ema10"
default_conf['indicators2'] = "macd"
default_conf['pairs'] = ["ETH/BTC", "LTC/BTC"]

candle_mock = MagicMock()
store_mock = MagicMock()
mocker.patch.multiple(
"freqtrade.plot.plotting",
generate_candlestick_graph=candle_mock,
store_plot_file=store_mock
)
analyse_and_plot_pairs(default_conf)

# Both mocks should be called once per pair
assert candle_mock.call_count == 2
assert store_mock.call_count == 2

assert candle_mock.call_args_list[0][1]['indicators1'] == ['sma5', 'ema10']
assert candle_mock.call_args_list[0][1]['indicators2'] == ['macd']

assert log_has("End of plotting process. 2 plots generated", caplog)

0 comments on commit 29076ac

Please sign in to comment.