mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-16 21:01:14 +00:00
feat: ensure spaces are valid identifiers
This commit is contained in:
@@ -192,6 +192,10 @@ def detect_all_parameters(
|
|||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"Conflicting parameter space for {attr_name}: {auto_category} vs {attr.category}."
|
f"Conflicting parameter space for {attr_name}: {auto_category} vs {attr.category}."
|
||||||
)
|
)
|
||||||
|
if attr.category in ("all", "default") or attr.category.isidentifier() is False:
|
||||||
|
raise OperationalException(
|
||||||
|
f"'{attr.category}' is not a valid space. Parameter: {attr_name}."
|
||||||
|
)
|
||||||
attr.name = attr_name
|
attr.name = attr_name
|
||||||
result[attr.category][attr_name] = attr
|
result[attr.category][attr_name] = attr
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -952,6 +952,7 @@ def test_auto_hyperopt_interface(default_conf):
|
|||||||
|
|
||||||
with pytest.raises(OperationalException, match=r"Conflicting parameter space.*"):
|
with pytest.raises(OperationalException, match=r"Conflicting parameter space.*"):
|
||||||
detect_all_parameters(strategy.__class__)
|
detect_all_parameters(strategy.__class__)
|
||||||
|
del strategy.__class__.sell_rsi
|
||||||
|
|
||||||
strategy.__class__.exit22_rsi = IntParameter([0, 10], default=5)
|
strategy.__class__.exit22_rsi = IntParameter([0, 10], default=5)
|
||||||
|
|
||||||
@@ -960,6 +961,20 @@ def test_auto_hyperopt_interface(default_conf):
|
|||||||
):
|
):
|
||||||
detect_all_parameters(strategy.__class__)
|
detect_all_parameters(strategy.__class__)
|
||||||
|
|
||||||
|
# Invalid parameter space
|
||||||
|
strategy.__class__.exit22_rsi = IntParameter([0, 10], default=5, space="all")
|
||||||
|
with pytest.raises(
|
||||||
|
OperationalException, match=r"'all' is not a valid space\. Parameter: exit22_rsi\."
|
||||||
|
):
|
||||||
|
detect_all_parameters(strategy.__class__)
|
||||||
|
|
||||||
|
strategy.__class__.exit22_rsi = IntParameter([0, 10], default=5, space="hello:world:22")
|
||||||
|
with pytest.raises(
|
||||||
|
OperationalException,
|
||||||
|
match=r"'hello:world:22' is not a valid space\. Parameter: exit22_rsi\.",
|
||||||
|
):
|
||||||
|
detect_all_parameters(strategy.__class__)
|
||||||
|
|
||||||
|
|
||||||
def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog):
|
def test_auto_hyperopt_interface_loadparams(default_conf, mocker, caplog):
|
||||||
default_conf.update({"strategy": "HyperoptableStrategy"})
|
default_conf.update({"strategy": "HyperoptableStrategy"})
|
||||||
|
|||||||
Reference in New Issue
Block a user