ruff format: update testcommands

This commit is contained in:
Matthias
2024-05-12 15:47:54 +02:00
parent adeb93dc9c
commit e4796fd85b
2 changed files with 819 additions and 626 deletions

View File

@@ -16,77 +16,72 @@ from tests.conftest import get_args, log_has_re
def test_validate_is_float(): def test_validate_is_float():
assert validate_is_float('2.0') assert validate_is_float("2.0")
assert validate_is_float('2.1') assert validate_is_float("2.1")
assert validate_is_float('0.1') assert validate_is_float("0.1")
assert validate_is_float('-0.5') assert validate_is_float("-0.5")
assert not validate_is_float('-0.5e') assert not validate_is_float("-0.5e")
def test_validate_is_int(): def test_validate_is_int():
assert validate_is_int('2') assert validate_is_int("2")
assert validate_is_int('6') assert validate_is_int("6")
assert validate_is_int('-1') assert validate_is_int("-1")
assert validate_is_int('500') assert validate_is_int("500")
assert not validate_is_int('2.0') assert not validate_is_int("2.0")
assert not validate_is_int('2.1') assert not validate_is_int("2.1")
assert not validate_is_int('-2.1') assert not validate_is_int("-2.1")
assert not validate_is_int('-ee') assert not validate_is_int("-ee")
@pytest.mark.parametrize('exchange', ['bybit', 'binance', 'kraken']) @pytest.mark.parametrize("exchange", ["bybit", "binance", "kraken"])
def test_start_new_config(mocker, caplog, exchange): def test_start_new_config(mocker, caplog, exchange):
wt_mock = mocker.patch.object(Path, "write_text", MagicMock()) wt_mock = mocker.patch.object(Path, "write_text", MagicMock())
mocker.patch.object(Path, "exists", MagicMock(return_value=True)) mocker.patch.object(Path, "exists", MagicMock(return_value=True))
unlink_mock = mocker.patch.object(Path, "unlink", MagicMock()) unlink_mock = mocker.patch.object(Path, "unlink", MagicMock())
mocker.patch('freqtrade.commands.build_config_commands.ask_user_overwrite', return_value=True) mocker.patch("freqtrade.commands.build_config_commands.ask_user_overwrite", return_value=True)
sample_selections = { sample_selections = {
'max_open_trades': 3, "max_open_trades": 3,
'stake_currency': 'USDT', "stake_currency": "USDT",
'stake_amount': 100, "stake_amount": 100,
'fiat_display_currency': 'EUR', "fiat_display_currency": "EUR",
'timeframe': '15m', "timeframe": "15m",
'dry_run': True, "dry_run": True,
'trading_mode': 'spot', "trading_mode": "spot",
'margin_mode': '', "margin_mode": "",
'exchange_name': exchange, "exchange_name": exchange,
'exchange_key': 'sampleKey', "exchange_key": "sampleKey",
'exchange_secret': 'Samplesecret', "exchange_secret": "Samplesecret",
'telegram': False, "telegram": False,
'telegram_token': 'asdf1244', "telegram_token": "asdf1244",
'telegram_chat_id': '1144444', "telegram_chat_id": "1144444",
'api_server': False, "api_server": False,
'api_server_listen_addr': '127.0.0.1', "api_server_listen_addr": "127.0.0.1",
'api_server_username': 'freqtrader', "api_server_username": "freqtrader",
'api_server_password': 'MoneyMachine', "api_server_password": "MoneyMachine",
} }
mocker.patch('freqtrade.commands.build_config_commands.ask_user_config', mocker.patch(
return_value=sample_selections) "freqtrade.commands.build_config_commands.ask_user_config", return_value=sample_selections
args = [ )
"new-config", args = ["new-config", "--config", "coolconfig.json"]
"--config",
"coolconfig.json"
]
start_new_config(get_args(args)) start_new_config(get_args(args))
assert log_has_re("Writing config to .*", caplog) assert log_has_re("Writing config to .*", caplog)
assert wt_mock.call_count == 1 assert wt_mock.call_count == 1
assert unlink_mock.call_count == 1 assert unlink_mock.call_count == 1
result = rapidjson.loads(wt_mock.call_args_list[0][0][0], result = rapidjson.loads(
parse_mode=rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS) wt_mock.call_args_list[0][0][0],
assert result['exchange']['name'] == exchange parse_mode=rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS,
assert result['timeframe'] == '15m' )
assert result["exchange"]["name"] == exchange
assert result["timeframe"] == "15m"
def test_start_new_config_exists(mocker, caplog): def test_start_new_config_exists(mocker, caplog):
mocker.patch.object(Path, "exists", MagicMock(return_value=True)) mocker.patch.object(Path, "exists", MagicMock(return_value=True))
mocker.patch('freqtrade.commands.build_config_commands.ask_user_overwrite', return_value=False) mocker.patch("freqtrade.commands.build_config_commands.ask_user_overwrite", return_value=False)
args = [ args = ["new-config", "--config", "coolconfig.json"]
"new-config",
"--config",
"coolconfig.json"
]
with pytest.raises(OperationalException, match=r"Configuration .* already exists\."): with pytest.raises(OperationalException, match=r"Configuration .* already exists\."):
start_new_config(get_args(args)) start_new_config(get_args(args))
@@ -95,15 +90,17 @@ def test_ask_user_overwrite(mocker):
""" """
Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test. Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test.
""" """
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt', prompt_mock = mocker.patch(
return_value={'overwrite': False}) "freqtrade.commands.build_config_commands.prompt", return_value={"overwrite": False}
assert not ask_user_overwrite(Path('test.json')) )
assert not ask_user_overwrite(Path("test.json"))
assert prompt_mock.call_count == 1 assert prompt_mock.call_count == 1
prompt_mock.reset_mock() prompt_mock.reset_mock()
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt', prompt_mock = mocker.patch(
return_value={'overwrite': True}) "freqtrade.commands.build_config_commands.prompt", return_value={"overwrite": True}
assert ask_user_overwrite(Path('test.json')) )
assert ask_user_overwrite(Path("test.json"))
assert prompt_mock.call_count == 1 assert prompt_mock.call_count == 1
@@ -111,14 +108,14 @@ def test_ask_user_config(mocker):
""" """
Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test. Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test.
""" """
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt', prompt_mock = mocker.patch(
return_value={'overwrite': False}) "freqtrade.commands.build_config_commands.prompt", return_value={"overwrite": False}
)
answers = ask_user_config() answers = ask_user_config()
assert isinstance(answers, dict) assert isinstance(answers, dict)
assert prompt_mock.call_count == 1 assert prompt_mock.call_count == 1
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt', prompt_mock = mocker.patch("freqtrade.commands.build_config_commands.prompt", return_value={})
return_value={})
with pytest.raises(OperationalException, match=r"User interrupted interactive questions\."): with pytest.raises(OperationalException, match=r"User interrupted interactive questions\."):
ask_user_config() ask_user_config()

File diff suppressed because it is too large Load Diff