Update tests to not use Namespace

This commit is contained in:
Matthias 2019-09-12 20:25:27 +02:00
parent e6ccc1427c
commit 4d566e8bad
5 changed files with 55 additions and 53 deletions

View File

@ -11,7 +11,6 @@ if sys.version_info < (3, 6):
# flake8: noqa E402
import logging
from argparse import Namespace
from typing import Any, List
from freqtrade import OperationalException

View File

@ -12,48 +12,48 @@ def test_parse_args_none() -> None:
arguments = Arguments([])
assert isinstance(arguments, Arguments)
x = arguments.get_parsed_arg()
assert isinstance(x, argparse.Namespace)
assert isinstance(x, dict)
assert isinstance(arguments.parser, argparse.ArgumentParser)
def test_parse_args_defaults() -> None:
args = Arguments([]).get_parsed_arg()
assert args.config == ['config.json']
assert args.strategy_path is None
assert args.datadir is None
assert args.verbosity == 0
assert args["config"] == ['config.json']
assert args["strategy_path"] is None
assert args["datadir"] is None
assert args["verbosity"] == 0
def test_parse_args_config() -> None:
args = Arguments(['-c', '/dev/null']).get_parsed_arg()
assert args.config == ['/dev/null']
assert args["config"] == ['/dev/null']
args = Arguments(['--config', '/dev/null']).get_parsed_arg()
assert args.config == ['/dev/null']
assert args["config"] == ['/dev/null']
args = Arguments(['--config', '/dev/null',
'--config', '/dev/zero'],).get_parsed_arg()
assert args.config == ['/dev/null', '/dev/zero']
assert args["config"] == ['/dev/null', '/dev/zero']
def test_parse_args_db_url() -> None:
args = Arguments(['--db-url', 'sqlite:///test.sqlite']).get_parsed_arg()
assert args.db_url == 'sqlite:///test.sqlite'
assert args["db_url"] == 'sqlite:///test.sqlite'
def test_parse_args_verbose() -> None:
args = Arguments(['-v']).get_parsed_arg()
assert args.verbosity == 1
assert args["verbosity"] == 1
args = Arguments(['--verbose']).get_parsed_arg()
assert args.verbosity == 1
assert args["verbosity"] == 1
def test_common_scripts_options() -> None:
args = Arguments(['download-data', '-p', 'ETH/BTC', 'XRP/BTC']).get_parsed_arg()
assert args.pairs == ['ETH/BTC', 'XRP/BTC']
assert hasattr(args, "func")
assert args["pairs"] == ['ETH/BTC', 'XRP/BTC']
assert "func" in args
def test_parse_args_version() -> None:
@ -68,7 +68,7 @@ def test_parse_args_invalid() -> None:
def test_parse_args_strategy() -> None:
args = Arguments(['--strategy', 'SomeStrategy']).get_parsed_arg()
assert args.strategy == 'SomeStrategy'
assert args["strategy"] == 'SomeStrategy'
def test_parse_args_strategy_invalid() -> None:
@ -78,7 +78,7 @@ def test_parse_args_strategy_invalid() -> None:
def test_parse_args_strategy_path() -> None:
args = Arguments(['--strategy-path', '/some/path']).get_parsed_arg()
assert args.strategy_path == '/some/path'
assert args["strategy_path"] == '/some/path'
def test_parse_args_strategy_path_invalid() -> None:
@ -105,14 +105,14 @@ def test_parse_args_backtesting_custom() -> None:
'SampleStrategy'
]
call_args = Arguments(args).get_parsed_arg()
assert call_args.config == ['test_conf.json']
assert call_args.verbosity == 0
assert call_args.subparser == 'backtesting'
assert call_args.func is not None
assert call_args.ticker_interval == '1m'
assert call_args.refresh_pairs is True
assert type(call_args.strategy_list) is list
assert len(call_args.strategy_list) == 2
assert call_args["config"] == ['test_conf.json']
assert call_args["verbosity"] == 0
assert call_args["subparser"] == 'backtesting'
assert call_args["func"] is not None
assert call_args["ticker_interval"] == '1m'
assert call_args["refresh_pairs"] is True
assert type(call_args["strategy_list"]) is list
assert len(call_args["strategy_list"]) == 2
def test_parse_args_hyperopt_custom() -> None:
@ -123,12 +123,13 @@ def test_parse_args_hyperopt_custom() -> None:
'--spaces', 'buy'
]
call_args = Arguments(args).get_parsed_arg()
assert call_args.config == ['test_conf.json']
assert call_args.epochs == 20
assert call_args.verbosity == 0
assert call_args.subparser == 'hyperopt'
assert call_args.spaces == ['buy']
assert call_args.func is not None
assert call_args["config"] == ['test_conf.json']
assert call_args["epochs"] == 20
assert call_args["verbosity"] == 0
assert call_args["subparser"] == 'hyperopt'
assert call_args["spaces"] == ['buy']
assert call_args["func"] is not None
assert callable(call_args["func"])
def test_download_data_options() -> None:
@ -139,12 +140,12 @@ def test_download_data_options() -> None:
'--days', '30',
'--exchange', 'binance'
]
args = Arguments(args).get_parsed_arg()
pargs = Arguments(args).get_parsed_arg()
assert args.pairs_file == 'file_with_pairs'
assert args.datadir == 'datadir/directory'
assert args.days == 30
assert args.exchange == 'binance'
assert pargs["pairs_file"] == 'file_with_pairs'
assert pargs["datadir"] == 'datadir/directory'
assert pargs["days"] == 30
assert pargs["exchange"] == 'binance'
def test_plot_dataframe_options() -> None:
@ -158,10 +159,10 @@ def test_plot_dataframe_options() -> None:
]
pargs = Arguments(args).get_parsed_arg()
assert pargs.indicators1 == ["sma10", "sma100"]
assert pargs.indicators2 == ["macd", "fastd", "fastk"]
assert pargs.plot_limit == 30
assert pargs.pairs == ["UNITTEST/BTC"]
assert pargs["indicators1"] == ["sma10", "sma100"]
assert pargs["indicators2"] == ["macd", "fastd", "fastk"]
assert pargs["plot_limit"] == 30
assert pargs["pairs"] == ["UNITTEST/BTC"]
def test_plot_profit_options() -> None:
@ -173,9 +174,9 @@ def test_plot_profit_options() -> None:
]
pargs = Arguments(args).get_parsed_arg()
assert pargs.trade_source == "DB"
assert pargs.pairs == ["UNITTEST/BTC"]
assert pargs.db_url == "sqlite:///whatever.sqlite"
assert pargs["trade_source"] == "DB"
assert pargs["pairs"] == ["UNITTEST/BTC"]
assert pargs["db_url"] == "sqlite:///whatever.sqlite"
def test_check_int_positive() -> None:

View File

@ -871,7 +871,7 @@ def test_pairlist_resolving_fallback(mocker):
args = Arguments(arglist).get_parsed_arg()
# Fix flaky tests if config.json exists
args.config = None
args["config"] = None
configuration = Configuration(args)
config = configuration.get_config()

View File

@ -27,11 +27,12 @@ def test_parse_args_backtesting(mocker) -> None:
main(['backtesting'])
assert backtesting_mock.call_count == 1
call_args = backtesting_mock.call_args[0][0]
assert call_args.config == ['config.json']
assert call_args.verbosity == 0
assert call_args.subparser == 'backtesting'
assert call_args.func is not None
assert call_args.ticker_interval is None
assert call_args["config"] == ['config.json']
assert call_args["verbosity"] == 0
assert call_args["subparser"] == 'backtesting'
assert call_args["func"] is not None
assert callable(call_args["func"])
assert call_args["ticker_interval"] is None
def test_main_start_hyperopt(mocker) -> None:
@ -42,10 +43,11 @@ def test_main_start_hyperopt(mocker) -> None:
main(['hyperopt'])
assert hyperopt_mock.call_count == 1
call_args = hyperopt_mock.call_args[0][0]
assert call_args.config == ['config.json']
assert call_args.verbosity == 0
assert call_args.subparser == 'hyperopt'
assert call_args.func is not None
assert call_args["config"] == ['config.json']
assert call_args["verbosity"] == 0
assert call_args["subparser"] == 'hyperopt'
assert call_args["func"] is not None
assert callable(call_args["func"])
def test_main_fatal_exception(mocker, default_conf, caplog) -> None:

View File

@ -344,7 +344,7 @@ def test_start_plot_profit_error(mocker):
argsp = get_args(args)
# Make sure we use no config. Details: #2241
# not resetting config causes random failures if config.json exists
argsp.config = []
argsp["config"] = []
with pytest.raises(OperationalException):
start_plot_profit(argsp)