From 3427df06539362f6f5838c537ee63d497a5c3778 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 8 Apr 2022 16:04:54 +0200 Subject: [PATCH] Add simple test for recursive loading --- config_examples/config_full.example.json | 1 + freqtrade/constants.py | 17 +++++++-------- tests/test_configuration.py | 23 ++++++++++++++++++++- tests/testdata/testconfigs/base_config.json | 12 +++++++++++ tests/testdata/testconfigs/pricing.json | 21 +++++++++++++++++++ tests/testdata/testconfigs/pricing2.json | 18 ++++++++++++++++ tests/testdata/testconfigs/recursive.json | 6 ++++++ tests/testdata/testconfigs/testconfig.json | 6 ++++++ 8 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 tests/testdata/testconfigs/base_config.json create mode 100644 tests/testdata/testconfigs/pricing.json create mode 100644 tests/testdata/testconfigs/pricing2.json create mode 100644 tests/testdata/testconfigs/recursive.json create mode 100644 tests/testdata/testconfigs/testconfig.json diff --git a/config_examples/config_full.example.json b/config_examples/config_full.example.json index 915db6c44..b41acb726 100644 --- a/config_examples/config_full.example.json +++ b/config_examples/config_full.example.json @@ -182,6 +182,7 @@ "disable_dataframe_checks": false, "strategy": "SampleStrategy", "strategy_path": "user_data/strategies/", + "files": [], "dataformat_ohlcv": "json", "dataformat_trades": "jsongz" } diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 8067c1f6a..c6a2ab5d3 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -91,15 +91,14 @@ SUPPORTED_FIAT = [ ] MINIMAL_CONFIG = { - 'stake_currency': '', - 'dry_run': True, - 'exchange': { - 'name': '', - 'key': '', - 'secret': '', - 'pair_whitelist': [], - 'ccxt_async_config': { - 'enableRateLimit': True, + "stake_currency": "", + "dry_run": True, + "exchange": { + "name": "", + "key": "", + "secret": "", + "pair_whitelist": [], + "ccxt_async_config": { } } } diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 19355b9eb..39e56f075 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -18,7 +18,8 @@ from freqtrade.configuration.deprecated_settings import (check_conflicting_setti process_removed_setting, process_temporary_deprecated_settings) from freqtrade.configuration.environment_vars import flat_vars_to_nested_dict -from freqtrade.configuration.load_config import load_config_file, load_file, log_config_error_range +from freqtrade.configuration.load_config import (load_config_file, load_file, load_from_files, + log_config_error_range) from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL, ENV_VAR_PREFIX from freqtrade.enums import RunMode from freqtrade.exceptions import OperationalException @@ -206,6 +207,26 @@ def test_from_config(default_conf, mocker, caplog) -> None: assert isinstance(validated_conf['user_data_dir'], Path) +def test_from_recursive_files(testdatadir) -> None: + files = testdatadir / "testconfigs/testconfig.json" + + conf = Configuration.from_files([files]) + + assert conf + # Exchange comes from "the first config" + assert conf['exchange'] + # Pricing comes from the 2nd config + assert conf['entry_pricing'] + assert conf['entry_pricing']['price_side'] == "same" + assert conf['exit_pricing'] + # The other key comes from pricing2, which is imported by pricing.json + assert conf['exit_pricing']['price_side'] == "other" + + files = testdatadir / "testconfigs/recursive.json" + with pytest.raises(OperationalException, match="Config loop detected."): + load_from_files([files]) + + def test_print_config(default_conf, mocker, caplog) -> None: conf1 = deepcopy(default_conf) # Delete non-json elements from default_conf diff --git a/tests/testdata/testconfigs/base_config.json b/tests/testdata/testconfigs/base_config.json new file mode 100644 index 000000000..d15c5890b --- /dev/null +++ b/tests/testdata/testconfigs/base_config.json @@ -0,0 +1,12 @@ +{ + "stake_currency": "", + "dry_run": true, + "exchange": { + "name": "", + "key": "", + "secret": "", + "pair_whitelist": [], + "ccxt_async_config": { + } + } +} diff --git a/tests/testdata/testconfigs/pricing.json b/tests/testdata/testconfigs/pricing.json new file mode 100644 index 000000000..d8868443f --- /dev/null +++ b/tests/testdata/testconfigs/pricing.json @@ -0,0 +1,21 @@ +{ + "entry_pricing": { + "price_side": "same", + "use_order_book": true, + "order_book_top": 1, + "price_last_balance": 0.0, + "check_depth_of_market": { + "enabled": false, + "bids_to_ask_delta": 1 + } + }, + "exit_pricing":{ + "price_side": "same", + "use_order_book": true, + "order_book_top": 1, + "price_last_balance": 0.0 + }, + "files": [ + "pricing2.json" + ] +} diff --git a/tests/testdata/testconfigs/pricing2.json b/tests/testdata/testconfigs/pricing2.json new file mode 100644 index 000000000..094783a60 --- /dev/null +++ b/tests/testdata/testconfigs/pricing2.json @@ -0,0 +1,18 @@ +{ + "entry_pricing": { + "price_side": "same", + "use_order_book": true, + "order_book_top": 1, + "price_last_balance": 0.0, + "check_depth_of_market": { + "enabled": false, + "bids_to_ask_delta": 1 + } + }, + "exit_pricing":{ + "price_side": "other", + "use_order_book": true, + "order_book_top": 1, + "price_last_balance": 0.0 + } +} diff --git a/tests/testdata/testconfigs/recursive.json b/tests/testdata/testconfigs/recursive.json new file mode 100644 index 000000000..28d8ce05a --- /dev/null +++ b/tests/testdata/testconfigs/recursive.json @@ -0,0 +1,6 @@ +{ + // This file fails as it's loading itself over and over + "files": [ + "./recursive.json" + ] +} diff --git a/tests/testdata/testconfigs/testconfig.json b/tests/testdata/testconfigs/testconfig.json new file mode 100644 index 000000000..557926097 --- /dev/null +++ b/tests/testdata/testconfigs/testconfig.json @@ -0,0 +1,6 @@ +{ + "files": [ + "base_config.json", + "pricing.json" + ] +}