Merge pull request #9975 from freqtrade/feat/configError

exception ConfigurationError
This commit is contained in:
Matthias
2024-03-21 08:38:45 +01:00
committed by GitHub
20 changed files with 113 additions and 86 deletions
+4 -3
View File
@@ -51,15 +51,16 @@ def test_start_trading_fail(mocker, caplog):
'trade',
'-c', 'tests/testdata/testconfigs/main_test_config.json'
]
start_trading(get_args(args))
with pytest.raises(OperationalException):
start_trading(get_args(args))
assert exitmock.call_count == 1
exitmock.reset_mock()
caplog.clear()
mocker.patch("freqtrade.worker.Worker.__init__", MagicMock(side_effect=OperationalException))
start_trading(get_args(args))
with pytest.raises(OperationalException):
start_trading(get_args(args))
assert exitmock.call_count == 0
assert log_has('Fatal exception!', caplog)
def test_start_webserver(mocker, caplog):
+5 -5
View File
@@ -11,8 +11,8 @@ from numpy import NaN
from pandas import DataFrame
from freqtrade.enums import CandleType, MarginMode, RunMode, TradingMode
from freqtrade.exceptions import (DDosProtection, DependencyException, ExchangeError,
InsufficientFundsError, InvalidOrderException,
from freqtrade.exceptions import (ConfigurationError, DDosProtection, DependencyException,
ExchangeError, InsufficientFundsError, InvalidOrderException,
OperationalException, PricingError, TemporaryError)
from freqtrade.exchange import (Binance, Bybit, Exchange, Kraken, market_is_active,
timeframe_to_prev_date)
@@ -595,7 +595,7 @@ def test_validate_stakecurrency_error(default_conf, mocker, caplog):
mocker.patch(f'{EXMS}.validate_pairs')
mocker.patch(f'{EXMS}.validate_timeframes')
mocker.patch(f'{EXMS}._load_async_markets')
with pytest.raises(OperationalException,
with pytest.raises(ConfigurationError,
match=r'XRP is not available as stake on .*'
'Available currencies are: BTC, ETH, USDT'):
Exchange(default_conf)
@@ -800,12 +800,12 @@ def test_validate_timeframes_failed(default_conf, mocker):
mocker.patch(f'{EXMS}.validate_pairs')
mocker.patch(f'{EXMS}.validate_stakecurrency')
mocker.patch(f'{EXMS}.validate_pricing')
with pytest.raises(OperationalException,
with pytest.raises(ConfigurationError,
match=r"Invalid timeframe '3m'. This exchange supports.*"):
Exchange(default_conf)
default_conf["timeframe"] = "15s"
with pytest.raises(OperationalException,
with pytest.raises(ConfigurationError,
match=r"Timeframes < 1m are currently not supported by Freqtrade."):
Exchange(default_conf)
+17 -1
View File
@@ -8,7 +8,7 @@ import pytest
from freqtrade.commands import Arguments
from freqtrade.enums import State
from freqtrade.exceptions import FreqtradeException, OperationalException
from freqtrade.exceptions import ConfigurationError, FreqtradeException, OperationalException
from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.main import main
from freqtrade.worker import Worker
@@ -141,6 +141,22 @@ def test_main_operational_exception1(mocker, default_conf, caplog) -> None:
assert log_has_re(r'SIGINT.*', caplog)
def test_main_ConfigurationError(mocker, default_conf, caplog) -> None:
patch_exchange(mocker)
mocker.patch(
'freqtrade.commands.list_commands.list_available_exchanges',
MagicMock(side_effect=ConfigurationError('Oh snap!'))
)
patched_configuration_load_config_file(mocker, default_conf)
args = ['list-exchanges']
# Test Main + the KeyboardInterrupt exception
with pytest.raises(SystemExit):
main(args)
assert log_has_re('Configuration error: Oh snap!', caplog)
def test_main_reload_config(mocker, default_conf, caplog) -> None:
patch_exchange(mocker)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cleanup', MagicMock())