Fix test_dataframe when ran standalone (#546)
* Fix dataframe test when ran standalone * Fix standalone tests in hyperopt and optimize tests
This commit is contained in:
parent
480d3876b8
commit
e907c48438
@ -7,7 +7,7 @@ import pandas as pd
|
|||||||
|
|
||||||
from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
|
from freqtrade.optimize.hyperopt import calculate_loss, TARGET_TRADES, EXPECTED_MAX_PROFIT, start, \
|
||||||
log_results, save_trials, read_trials, generate_roi_table, has_space
|
log_results, save_trials, read_trials, generate_roi_table, has_space
|
||||||
|
from freqtrade.strategy.strategy import Strategy
|
||||||
import freqtrade.optimize.hyperopt as hyperopt
|
import freqtrade.optimize.hyperopt as hyperopt
|
||||||
|
|
||||||
|
|
||||||
@ -72,6 +72,7 @@ def test_start_calls_fmin(mocker):
|
|||||||
|
|
||||||
args = mocker.Mock(epochs=1, config='config.json.example', mongodb=False,
|
args = mocker.Mock(epochs=1, config='config.json.example', mongodb=False,
|
||||||
timerange=None, spaces='all')
|
timerange=None, spaces='all')
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
start(args)
|
start(args)
|
||||||
|
|
||||||
mock_fmin.assert_called_once()
|
mock_fmin.assert_called_once()
|
||||||
@ -86,6 +87,7 @@ def test_start_uses_mongotrials(mocker):
|
|||||||
|
|
||||||
args = mocker.Mock(epochs=1, config='config.json.example', mongodb=True,
|
args = mocker.Mock(epochs=1, config='config.json.example', mongodb=True,
|
||||||
timerange=None, spaces='all')
|
timerange=None, spaces='all')
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
start(args)
|
start(args)
|
||||||
|
|
||||||
mock_mongotrials.assert_called_once()
|
mock_mongotrials.assert_called_once()
|
||||||
@ -149,6 +151,7 @@ def test_fmin_best_results(mocker, caplog):
|
|||||||
|
|
||||||
args = mocker.Mock(epochs=1, config='config.json.example',
|
args = mocker.Mock(epochs=1, config='config.json.example',
|
||||||
timerange=None, spaces='all')
|
timerange=None, spaces='all')
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
start(args)
|
start(args)
|
||||||
|
|
||||||
exists = [
|
exists = [
|
||||||
@ -166,6 +169,7 @@ def test_fmin_best_results(mocker, caplog):
|
|||||||
|
|
||||||
def test_fmin_throw_value_error(mocker, caplog):
|
def test_fmin_throw_value_error(mocker, caplog):
|
||||||
caplog.set_level(logging.INFO)
|
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.hyperopt.MongoTrials', return_value=create_trials(mocker))
|
||||||
mocker.patch('freqtrade.optimize.tickerdata_to_dataframe')
|
mocker.patch('freqtrade.optimize.tickerdata_to_dataframe')
|
||||||
mocker.patch('freqtrade.optimize.load_data')
|
mocker.patch('freqtrade.optimize.load_data')
|
||||||
@ -173,6 +177,7 @@ def test_fmin_throw_value_error(mocker, caplog):
|
|||||||
|
|
||||||
args = mocker.Mock(epochs=1, config='config.json.example',
|
args = mocker.Mock(epochs=1, config='config.json.example',
|
||||||
timerange=None, spaces='all')
|
timerange=None, spaces='all')
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
start(args)
|
start(args)
|
||||||
|
|
||||||
exists = [
|
exists = [
|
||||||
@ -209,7 +214,7 @@ def test_resuming_previous_hyperopt_results_succeeds(mocker):
|
|||||||
mongodb=False,
|
mongodb=False,
|
||||||
timerange=None,
|
timerange=None,
|
||||||
spaces='all')
|
spaces='all')
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
start(args)
|
start(args)
|
||||||
|
|
||||||
mock_read.assert_called_once()
|
mock_read.assert_called_once()
|
||||||
|
@ -10,6 +10,7 @@ from freqtrade.exchange import Bittrex
|
|||||||
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
|
from freqtrade.optimize.__init__ import make_testdata_path, download_pairs,\
|
||||||
download_backtesting_testdata, load_tickerdata_file, trim_tickerlist, file_dump_json
|
download_backtesting_testdata, load_tickerdata_file, trim_tickerlist, file_dump_json
|
||||||
from freqtrade.tests.conftest import log_has
|
from freqtrade.tests.conftest import log_has
|
||||||
|
from freqtrade.strategy.strategy import Strategy
|
||||||
|
|
||||||
# Change this if modifying BTC_UNITEST testdatafile
|
# Change this if modifying BTC_UNITEST testdatafile
|
||||||
_BTC_UNITTEST_LENGTH = 13681
|
_BTC_UNITTEST_LENGTH = 13681
|
||||||
@ -218,6 +219,7 @@ def test_init(default_conf, mocker):
|
|||||||
|
|
||||||
|
|
||||||
def test_tickerdata_to_dataframe():
|
def test_tickerdata_to_dataframe():
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
timerange = ((None, 'line'), None, -100)
|
timerange = ((None, 'line'), None, -100)
|
||||||
tick = load_tickerdata_file(None, 'BTC_UNITEST', 1, timerange=timerange)
|
tick = load_tickerdata_file(None, 'BTC_UNITEST', 1, timerange=timerange)
|
||||||
tickerlist = {'BTC_UNITEST': tick}
|
tickerlist = {'BTC_UNITEST': tick}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import pandas
|
import pandas
|
||||||
import freqtrade.optimize
|
import freqtrade.optimize
|
||||||
from freqtrade import analyze
|
from freqtrade import analyze
|
||||||
|
from freqtrade.strategy.strategy import Strategy
|
||||||
|
|
||||||
_pairs = ['BTC_ETH']
|
_pairs = ['BTC_ETH']
|
||||||
|
|
||||||
@ -17,11 +18,13 @@ def load_dataframe_pair(pairs):
|
|||||||
|
|
||||||
|
|
||||||
def test_dataframe_load():
|
def test_dataframe_load():
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
dataframe = load_dataframe_pair(_pairs)
|
dataframe = load_dataframe_pair(_pairs)
|
||||||
assert isinstance(dataframe, pandas.core.frame.DataFrame)
|
assert isinstance(dataframe, pandas.core.frame.DataFrame)
|
||||||
|
|
||||||
|
|
||||||
def test_dataframe_columns_exists():
|
def test_dataframe_columns_exists():
|
||||||
|
Strategy().init({'strategy': 'default_strategy'})
|
||||||
dataframe = load_dataframe_pair(_pairs)
|
dataframe = load_dataframe_pair(_pairs)
|
||||||
assert 'high' in dataframe.columns
|
assert 'high' in dataframe.columns
|
||||||
assert 'low' in dataframe.columns
|
assert 'low' in dataframe.columns
|
||||||
|
Loading…
Reference in New Issue
Block a user