diff --git a/freqtrade/tests/test_configuration.py b/freqtrade/tests/test_configuration.py index d27405d91..8ba8f8289 100644 --- a/freqtrade/tests/test_configuration.py +++ b/freqtrade/tests/test_configuration.py @@ -6,6 +6,7 @@ Unit test file for configuration.py import json from copy import deepcopy from unittest.mock import MagicMock +from argparse import Namespace import pytest from jsonschema import ValidationError @@ -37,7 +38,7 @@ def test_load_config_invalid_pair(default_conf) -> None: conf['exchange']['pair_whitelist'].append('ETH-BTC') with pytest.raises(ValidationError, match=r'.*does not match.*'): - configuration = Configuration([]) + configuration = Configuration(Namespace()) configuration._validate_config(conf) @@ -49,7 +50,7 @@ def test_load_config_missing_attributes(default_conf) -> None: conf.pop('exchange') with pytest.raises(ValidationError, match=r'.*\'exchange\' is a required property.*'): - configuration = Configuration([]) + configuration = Configuration(Namespace()) configuration._validate_config(conf) @@ -61,7 +62,7 @@ def test_load_config_file(default_conf, mocker, caplog) -> None: read_data=json.dumps(default_conf) )) - configuration = Configuration([]) + configuration = Configuration(Namespace()) validated_conf = configuration._load_config_file('somefile') assert file_mock.call_count == 1 assert validated_conf.items() >= default_conf.items() @@ -79,7 +80,7 @@ def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None: read_data=json.dumps(conf) )) - Configuration([])._load_config_file('somefile') + Configuration(Namespace())._load_config_file('somefile') assert file_mock.call_count == 1 assert log_has('Validating configuration ...', caplog.record_tuples) @@ -92,7 +93,7 @@ def test_load_config_file_exception(mocker, caplog) -> None: 'freqtrade.configuration.open', MagicMock(side_effect=FileNotFoundError('File not found')) ) - configuration = Configuration([]) + configuration = Configuration(Namespace()) with pytest.raises(SystemExit): configuration._load_config_file('somefile') @@ -128,13 +129,13 @@ def test_load_config_with_params(default_conf, mocker) -> None: read_data=json.dumps(default_conf) )) - args = [ + arglist = [ '--dynamic-whitelist', '10', '--strategy', 'TestStrategy', '--strategy-path', '/some/path', '--dry-run-db', ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(arglist, '').get_parsed_arg() configuration = Configuration(args) validated_conf = configuration.load_config() @@ -174,12 +175,12 @@ def test_show_info(default_conf, mocker, caplog) -> None: read_data=json.dumps(default_conf) )) - args = [ + arglist = [ '--dynamic-whitelist', '10', '--strategy', 'TestStrategy', '--dry-run-db' ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(arglist, '').get_parsed_arg() configuration = Configuration(args) configuration.get_config() @@ -202,8 +203,8 @@ def test_show_info(default_conf, mocker, caplog) -> None: ) # Test the Dry run condition - configuration.config.update({'dry_run': False}) - configuration._load_common_config(configuration.config) + configuration.config.update({'dry_run': False}) # type: ignore + configuration._load_common_config(configuration.config) # type: ignore assert log_has( 'Dry run is disabled. (--dry_run_db ignored)', caplog.record_tuples @@ -218,13 +219,13 @@ def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> read_data=json.dumps(default_conf) )) - args = [ + arglist = [ '--config', 'config.json', '--strategy', 'DefaultStrategy', 'backtesting' ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(arglist, '').get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -262,7 +263,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non read_data=json.dumps(default_conf) )) - args = [ + arglist = [ '--config', 'config.json', '--strategy', 'DefaultStrategy', '--datadir', '/foo/bar', @@ -275,7 +276,7 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non '--export', '/bar/foo' ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(arglist, '').get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -326,14 +327,14 @@ def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None: read_data=json.dumps(default_conf) )) - args = [ + arglist = [ 'hyperopt', '--epochs', '10', '--use-mongodb', '--spaces', 'all', ] - args = Arguments(args, '').get_parsed_arg() + args = Arguments(arglist, '').get_parsed_arg() configuration = Configuration(args) config = configuration.get_config() @@ -357,7 +358,7 @@ def test_check_exchange(default_conf) -> None: Test the configuration validator with a missing attribute """ conf = deepcopy(default_conf) - configuration = Configuration([]) + configuration = Configuration(Namespace()) # Test a valid exchange conf.get('exchange').update({'name': 'BITTREX'})