chore: update patch_exchange to not override builtins

This commit is contained in:
Matthias 2024-07-05 09:10:55 +02:00
parent 1e287de589
commit 36a44575c7
5 changed files with 18 additions and 17 deletions

View File

@ -167,7 +167,7 @@ def test_list_timeframes(mocker, capsys):
"1h": "hour",
"1d": "day",
}
patch_exchange(mocker, api_mock=api_mock, id="bybit")
patch_exchange(mocker, api_mock=api_mock, exchange="bybit")
args = [
"list-timeframes",
]
@ -213,7 +213,7 @@ def test_list_timeframes(mocker, capsys):
"1d": "1d",
"3d": "3d",
}
patch_exchange(mocker, api_mock=api_mock, id="binance")
patch_exchange(mocker, api_mock=api_mock, exchange="binance")
# Test with --exchange binance
args = [
"list-timeframes",
@ -258,7 +258,7 @@ def test_list_timeframes(mocker, capsys):
def test_list_markets(mocker, markets_static, capsys):
api_mock = MagicMock()
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
# Test with no --config
args = [
@ -286,7 +286,7 @@ def test_list_markets(mocker, markets_static, capsys):
"LTC/ETH, LTC/USD, NEO/BTC, TKN/BTC, XLTCUSDT, XRP/BTC.\n" in captured.out
)
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
# Test with --exchange
args = ["list-markets", "--exchange", "binance"]
pargs = get_args(args)
@ -295,7 +295,7 @@ def test_list_markets(mocker, markets_static, capsys):
captured = capsys.readouterr()
assert re.match("\nExchange Binance has 12 active markets:\n", captured.out)
patch_exchange(mocker, api_mock=api_mock, id="binance", mock_markets=markets_static)
patch_exchange(mocker, api_mock=api_mock, exchange="binance", mock_markets=markets_static)
# Test with --all: all markets
args = [
"list-markets",
@ -823,7 +823,7 @@ def test_download_data_no_markets(mocker, caplog):
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker, id="binance")
patch_exchange(mocker, exchange="binance")
mocker.patch(f"{EXMS}.get_markets", return_value={})
args = [
"download-data",
@ -952,7 +952,7 @@ def test_download_data_trades(mocker):
def test_download_data_data_invalid(mocker):
patch_exchange(mocker, id="kraken")
patch_exchange(mocker, exchange="kraken")
mocker.patch(f"{EXMS}.get_markets", return_value={})
args = [
"download-data",

View File

@ -137,7 +137,7 @@ def generate_trades_history(n_rows, start_date: Optional[datetime] = None, days=
random_timestamps_in_seconds = np.random.uniform(_start_timestamp, _end_timestamp, n_rows)
timestamp = pd.to_datetime(random_timestamps_in_seconds, unit="s")
id = [
trade_id = [
f"a{np.random.randint(1e6, 1e7 - 1)}cd{np.random.randint(100, 999)}" for _ in range(n_rows)
]
@ -155,7 +155,7 @@ def generate_trades_history(n_rows, start_date: Optional[datetime] = None, days=
df = pd.DataFrame(
{
"timestamp": timestamp,
"id": id,
"id": trade_id,
"type": None,
"side": side,
"price": price,
@ -236,12 +236,12 @@ def patched_configuration_load_config_file(mocker, config) -> None:
def patch_exchange(
mocker, api_mock=None, id="binance", mock_markets=True, mock_supported_modes=True
mocker, api_mock=None, exchange="binance", mock_markets=True, mock_supported_modes=True
) -> None:
mocker.patch(f"{EXMS}.validate_config", MagicMock())
mocker.patch(f"{EXMS}.validate_timeframes", MagicMock())
mocker.patch(f"{EXMS}.id", PropertyMock(return_value=id))
mocker.patch(f"{EXMS}.name", PropertyMock(return_value=id.title()))
mocker.patch(f"{EXMS}.id", PropertyMock(return_value=exchange))
mocker.patch(f"{EXMS}.name", PropertyMock(return_value=exchange.title()))
mocker.patch(f"{EXMS}.precisionMode", PropertyMock(return_value=2))
# Temporary patch ...
mocker.patch("freqtrade.exchange.bybit.Bybit.cache_leverage_tiers")
@ -254,7 +254,8 @@ def patch_exchange(
if mock_supported_modes:
mocker.patch(
f"freqtrade.exchange.{id}.{id.capitalize()}._supported_trading_mode_margin_pairs",
f"freqtrade.exchange.{exchange}.{exchange.capitalize()}"
"._supported_trading_mode_margin_pairs",
PropertyMock(
return_value=[
(TradingMode.MARGIN, MarginMode.CROSS),

View File

@ -14,7 +14,7 @@ def test_download_data_main_no_markets(mocker, caplog):
"freqtrade.data.history.history_utils.refresh_backtest_ohlcv_data",
MagicMock(return_value=["ETH/BTC", "XRP/BTC"]),
)
patch_exchange(mocker, id="binance")
patch_exchange(mocker, exchange="binance")
mocker.patch(f"{EXMS}.get_markets", return_value={})
config = setup_utils_configuration({"exchange": "binance"}, RunMode.UTIL_EXCHANGE)
config.update({"days": 20, "pairs": ["ETH/BTC", "XRP/BTC"], "timeframes": ["5m", "1h"]})
@ -91,7 +91,7 @@ def test_download_data_main_trades(mocker):
def test_download_data_main_data_invalid(mocker):
patch_exchange(mocker, id="kraken")
patch_exchange(mocker, exchange="kraken")
mocker.patch(f"{EXMS}.get_markets", return_value={})
config = setup_utils_configuration({"exchange": "kraken"}, RunMode.UTIL_EXCHANGE)
config.update(

View File

@ -17,7 +17,7 @@ def test_import_kraken_trades_from_csv(testdatadir, tmp_path, caplog, default_co
default_conf_usdt["exchange"]["name"] = "kraken"
patch_exchange(mocker, id="kraken")
patch_exchange(mocker, exchange="kraken")
mocker.patch(
f"{EXMS}.markets",
PropertyMock(

View File

@ -915,7 +915,7 @@ def test_execute_entry(
default_conf_usdt["margin_mode"] = margin_mode
mocker.patch("freqtrade.exchange.gate.Gate.validate_ordertypes")
patch_RPCManager(mocker)
patch_exchange(mocker, id=exchange_name)
patch_exchange(mocker, exchange=exchange_name)
freqtrade = FreqtradeBot(default_conf_usdt)
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
freqtrade.strategy.leverage = MagicMock(return_value=leverage)