Add some rudimentary tests for questions

This commit is contained in:
Matthias 2020-02-01 14:46:43 +01:00
parent d1a3a2d000
commit 12317b1c53

View File

@ -5,11 +5,33 @@ import pytest
import rapidjson import rapidjson
from freqtrade.commands.build_config_commands import (ask_user_config, from freqtrade.commands.build_config_commands import (ask_user_config,
start_new_config) ask_user_overwrite,
start_new_config,
validate_is_float,
validate_is_int)
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from tests.conftest import get_args, log_has_re from tests.conftest import get_args, log_has_re
def test_validate_is_float():
assert validate_is_float('2.0')
assert validate_is_float('2.1')
assert validate_is_float('0.1')
assert validate_is_float('-0.5')
assert not validate_is_float('-0.5e')
def test_validate_is_int():
assert validate_is_int('2')
assert validate_is_int('6')
assert validate_is_int('-1')
assert validate_is_int('500')
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('-ee')
@pytest.mark.parametrize('exchange', ['bittrex', 'binance', 'kraken', 'ftx']) @pytest.mark.parametrize('exchange', ['bittrex', 'binance', 'kraken', 'ftx'])
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())
@ -61,7 +83,34 @@ def test_start_new_config_exists(mocker, caplog):
start_new_config(get_args(args)) start_new_config(get_args(args))
def test_ask_user_config(): def test_ask_user_overwrite(mocker):
# TODO: Implement me """
pass Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test.
# assert ask_user_config() """
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt',
return_value={'overwrite': False})
assert not ask_user_overwrite(Path('test.json'))
assert prompt_mock.call_count == 1
prompt_mock.reset_mock()
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt',
return_value={'overwrite': True})
assert ask_user_overwrite(Path('test.json'))
assert prompt_mock.call_count == 1
def test_ask_user_config(mocker):
"""
Once https://github.com/tmbo/questionary/issues/35 is implemented, improve this test.
"""
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt',
return_value={'overwrite': False})
answers = ask_user_config()
assert isinstance(answers, dict)
assert prompt_mock.call_count == 1
prompt_mock = mocker.patch('freqtrade.commands.build_config_commands.prompt',
return_value={})
with pytest.raises(OperationalException, match=r"User interrupted interactive questions\."):
ask_user_config()