2018-02-12 06:10:21 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, C0103
|
|
|
|
|
|
|
|
"""
|
|
|
|
Unit test file for arguments.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import logging
|
2018-03-17 21:44:47 +00:00
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from freqtrade.arguments import Arguments
|
|
|
|
|
|
|
|
|
|
|
|
def test_arguments_object() -> None:
|
|
|
|
"""
|
|
|
|
Test the Arguments object has the mandatory methods
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
assert hasattr(Arguments, 'get_parsed_arg')
|
2018-03-05 01:51:57 +00:00
|
|
|
assert hasattr(Arguments, 'parse_args')
|
2018-02-12 06:10:21 +00:00
|
|
|
assert hasattr(Arguments, 'parse_timerange')
|
|
|
|
assert hasattr(Arguments, 'scripts_options')
|
|
|
|
|
|
|
|
|
|
|
|
# Parse common command-line-arguments. Used for all tools
|
|
|
|
def test_parse_args_none() -> None:
|
|
|
|
arguments = Arguments([], '')
|
|
|
|
assert isinstance(arguments, Arguments)
|
|
|
|
assert isinstance(arguments.parser, argparse.ArgumentParser)
|
|
|
|
assert isinstance(arguments.parser, argparse.ArgumentParser)
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_defaults() -> None:
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
assert args.config == 'config.json'
|
|
|
|
assert args.dynamic_whitelist is None
|
|
|
|
assert args.loglevel == logging.INFO
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_config() -> None:
|
|
|
|
args = Arguments(['-c', '/dev/null'], '').get_parsed_arg()
|
|
|
|
assert args.config == '/dev/null'
|
|
|
|
|
|
|
|
args = Arguments(['--config', '/dev/null'], '').get_parsed_arg()
|
|
|
|
assert args.config == '/dev/null'
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_verbose() -> None:
|
|
|
|
args = Arguments(['-v'], '').get_parsed_arg()
|
|
|
|
assert args.loglevel == logging.DEBUG
|
|
|
|
|
|
|
|
args = Arguments(['--verbose'], '').get_parsed_arg()
|
|
|
|
assert args.loglevel == logging.DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
def test_scripts_options() -> None:
|
2018-02-03 16:15:40 +00:00
|
|
|
arguments = Arguments(['-p', 'ETH/BTC'], '')
|
2018-02-12 06:10:21 +00:00
|
|
|
arguments.scripts_options()
|
|
|
|
args = arguments.get_parsed_arg()
|
2018-02-03 16:15:40 +00:00
|
|
|
assert args.pair == 'ETH/BTC'
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_version() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'0'):
|
|
|
|
Arguments(['--version'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['-c'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
2018-03-25 14:28:04 +00:00
|
|
|
def test_parse_args_strategy() -> None:
|
|
|
|
args = Arguments(['--strategy', 'SomeStrategy'], '').get_parsed_arg()
|
|
|
|
assert args.strategy == 'SomeStrategy'
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['--strategy'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_path() -> None:
|
|
|
|
args = Arguments(['--strategy-path', '/some/path'], '').get_parsed_arg()
|
|
|
|
assert args.strategy_path == '/some/path'
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_path_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['--strategy-path'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
def test_parse_args_dynamic_whitelist() -> None:
|
|
|
|
args = Arguments(['--dynamic-whitelist'], '').get_parsed_arg()
|
|
|
|
assert args.dynamic_whitelist == 20
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_dynamic_whitelist_10() -> None:
|
|
|
|
args = Arguments(['--dynamic-whitelist', '10'], '').get_parsed_arg()
|
|
|
|
assert args.dynamic_whitelist == 10
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_dynamic_whitelist_invalid_values() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['--dynamic-whitelist', 'abc'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_timerange_incorrect() -> None:
|
|
|
|
assert ((None, 'line'), None, -200) == Arguments.parse_timerange('-200')
|
|
|
|
assert (('line', None), 200, None) == Arguments.parse_timerange('200-')
|
2018-04-27 21:16:34 +00:00
|
|
|
assert (('index', 'index'), 200, 500) == Arguments.parse_timerange('200-500')
|
|
|
|
|
|
|
|
assert (('date', None), 1274486400, None) == Arguments.parse_timerange('20100522-')
|
|
|
|
assert ((None, 'date'), None, 1274486400) == Arguments.parse_timerange('-20100522')
|
2018-04-27 21:30:42 +00:00
|
|
|
timerange = Arguments.parse_timerange('20100522-20150730')
|
|
|
|
assert timerange == (('date', 'date'), 1274486400, 1438214400)
|
2018-04-27 21:16:34 +00:00
|
|
|
|
2018-06-02 19:46:54 +00:00
|
|
|
# Added test for unix timestamp - BTC genesis date
|
|
|
|
assert (('date', None), 1231006505, None) == Arguments.parse_timerange('1231006505-')
|
|
|
|
assert ((None, 'date'), None, 1233360000) == Arguments.parse_timerange('-1233360000')
|
|
|
|
timerange = Arguments.parse_timerange('1231006505-1233360000')
|
|
|
|
assert timerange == (('date', 'date'), 1231006505, 1233360000)
|
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
with pytest.raises(Exception, match=r'Incorrect syntax.*'):
|
|
|
|
Arguments.parse_timerange('-')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_backtesting_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['backtesting --ticker-interval'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['backtesting --ticker-interval', 'abc'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_backtesting_custom() -> None:
|
|
|
|
args = [
|
|
|
|
'-c', 'test_conf.json',
|
|
|
|
'backtesting',
|
|
|
|
'--live',
|
2018-03-24 09:21:59 +00:00
|
|
|
'--ticker-interval', '1m',
|
2018-02-12 06:10:21 +00:00
|
|
|
'--refresh-pairs-cached']
|
|
|
|
call_args = Arguments(args, '').get_parsed_arg()
|
|
|
|
assert call_args.config == 'test_conf.json'
|
|
|
|
assert call_args.live is True
|
|
|
|
assert call_args.loglevel == logging.INFO
|
|
|
|
assert call_args.subparser == 'backtesting'
|
|
|
|
assert call_args.func is not None
|
2018-03-24 09:21:59 +00:00
|
|
|
assert call_args.ticker_interval == '1m'
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.refresh_pairs is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_hyperopt_custom() -> None:
|
2018-03-04 08:51:22 +00:00
|
|
|
args = [
|
|
|
|
'-c', 'test_conf.json',
|
|
|
|
'hyperopt',
|
|
|
|
'--epochs', '20',
|
|
|
|
'--spaces', 'buy'
|
|
|
|
]
|
2018-02-12 06:10:21 +00:00
|
|
|
call_args = Arguments(args, '').get_parsed_arg()
|
|
|
|
assert call_args.config == 'test_conf.json'
|
|
|
|
assert call_args.epochs == 20
|
|
|
|
assert call_args.loglevel == logging.INFO
|
|
|
|
assert call_args.subparser == 'hyperopt'
|
2018-03-04 08:58:20 +00:00
|
|
|
assert call_args.spaces == ['buy']
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.func is not None
|