Skip to content

Commit

Permalink
Fix test_dataframe when ran standalone (#546)
Browse files Browse the repository at this point in the history
* Fix dataframe test when ran standalone

* Fix standalone tests in hyperopt and optimize tests
  • Loading branch information
xmatthias authored and gcarq committed Mar 15, 2018
1 parent 480d387 commit e907c48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions freqtrade/tests/optimize/test_hyperopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
log_results, save_trials, read_trials, generate_roi_table, has_space

from freqtrade.strategy.strategy import Strategy
import freqtrade.optimize.hyperopt as hyperopt


Expand Down Expand Up @@ -72,6 +72,7 @@ def test_start_calls_fmin(mocker):

args = mocker.Mock(epochs=1, config='config.json.example', mongodb=False,
timerange=None, spaces='all')
Strategy().init({'strategy': 'default_strategy'})
start(args)

mock_fmin.assert_called_once()
Expand All @@ -86,6 +87,7 @@ def test_start_uses_mongotrials(mocker):

args = mocker.Mock(epochs=1, config='config.json.example', mongodb=True,
timerange=None, spaces='all')
Strategy().init({'strategy': 'default_strategy'})
start(args)

mock_mongotrials.assert_called_once()
Expand Down Expand Up @@ -149,6 +151,7 @@ def test_fmin_best_results(mocker, caplog):

args = mocker.Mock(epochs=1, config='config.json.example',
timerange=None, spaces='all')
Strategy().init({'strategy': 'default_strategy'})
start(args)

exists = [
Expand All @@ -166,13 +169,15 @@ def test_fmin_best_results(mocker, caplog):

def test_fmin_throw_value_error(mocker, caplog):
caplog.set_level(logging.INFO)
Strategy().init({'strategy': 'default_strategy'})
mocker.patch('freqtrade.optimize.hyperopt.MongoTrials', return_value=create_trials(mocker))
mocker.patch('freqtrade.optimize.tickerdata_to_dataframe')
mocker.patch('freqtrade.optimize.load_data')
mocker.patch('freqtrade.optimize.hyperopt.fmin', side_effect=ValueError())

args = mocker.Mock(epochs=1, config='config.json.example',
timerange=None, spaces='all')
Strategy().init({'strategy': 'default_strategy'})
start(args)

exists = [
Expand Down Expand Up @@ -209,7 +214,7 @@ def test_resuming_previous_hyperopt_results_succeeds(mocker):
mongodb=False,
timerange=None,
spaces='all')

Strategy().init({'strategy': 'default_strategy'})
start(args)

mock_read.assert_called_once()
Expand Down
2 changes: 2 additions & 0 deletions freqtrade/tests/optimize/test_optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
download_backtesting_testdata, load_tickerdata_file, trim_tickerlist, file_dump_json
from freqtrade.tests.conftest import log_has
from freqtrade.strategy.strategy import Strategy

# Change this if modifying BTC_UNITEST testdatafile
_BTC_UNITTEST_LENGTH = 13681
Expand Down Expand Up @@ -218,6 +219,7 @@ def test_init(default_conf, mocker):


def test_tickerdata_to_dataframe():
Strategy().init({'strategy': 'default_strategy'})
timerange = ((None, 'line'), None, -100)
tick = load_tickerdata_file(None, 'BTC_UNITEST', 1, timerange=timerange)
tickerlist = {'BTC_UNITEST': tick}
Expand Down
3 changes: 3 additions & 0 deletions freqtrade/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pandas
import freqtrade.optimize
from freqtrade import analyze
from freqtrade.strategy.strategy import Strategy

_pairs = ['BTC_ETH']

Expand All @@ -17,11 +18,13 @@ def load_dataframe_pair(pairs):


def test_dataframe_load():
Strategy().init({'strategy': 'default_strategy'})
dataframe = load_dataframe_pair(_pairs)
assert isinstance(dataframe, pandas.core.frame.DataFrame)


def test_dataframe_columns_exists():
Strategy().init({'strategy': 'default_strategy'})
dataframe = load_dataframe_pair(_pairs)
assert 'high' in dataframe.columns
assert 'low' in dataframe.columns
Expand Down

0 comments on commit e907c48

Please sign in to comment.