Slightly enhance test cov

This commit is contained in:
Matthias 2024-03-29 15:52:35 +01:00
parent d047ac67a8
commit 411322357c

View File

@ -3,6 +3,12 @@ from unittest.mock import MagicMock
import pytest import pytest
from freqtrade_client import FtRestClient from freqtrade_client import FtRestClient
from freqtrade_client.ft_client import add_arguments, main_exec from freqtrade_client.ft_client import add_arguments, main_exec
from requests.exceptions import ConnectionError
def log_has(line, logs):
"""Check if line is found on some caplog's message."""
return any(line == message for message in logs.messages)
def get_rest_client(): def get_rest_client():
@ -32,6 +38,17 @@ def test_FtRestClient_call(method):
assert mock.call_count == 2 assert mock.call_count == 2
def test_FtRestClient_call_invalid(caplog):
client, _ = get_rest_client()
with pytest.raises(ValueError):
client._call('PUTTY', '/dummytest')
client._session.request = MagicMock(side_effect=ConnectionError())
client._call('GET', '/dummytest')
assert log_has('Connection error', caplog)
@pytest.mark.parametrize('method,args', [ @pytest.mark.parametrize('method,args', [
('start', []), ('start', []),
('stop', []), ('stop', []),
@ -67,6 +84,7 @@ def test_FtRestClient_call(method):
('delete_trade', [1]), ('delete_trade', [1]),
('cancel_open_order', [1]), ('cancel_open_order', [1]),
('whitelist', []), ('whitelist', []),
('blacklist', []),
('blacklist', ['XRP/USDT']), ('blacklist', ['XRP/USDT']),
('blacklist', ['XRP/USDT', 'BTC/USDT']), ('blacklist', ['XRP/USDT', 'BTC/USDT']),
('forcebuy', ['XRP/USDT']), ('forcebuy', ['XRP/USDT']),
@ -95,7 +113,7 @@ def test_FtRestClient_call_explicit_methods(method, args):
assert mock.call_count == 1 assert mock.call_count == 1
def test_ft_client(mocker, capsys): def test_ft_client(mocker, capsys, caplog):
with pytest.raises(SystemExit): with pytest.raises(SystemExit):
args = add_arguments(['-V']) args = add_arguments(['-V'])
@ -116,3 +134,17 @@ def test_ft_client(mocker, capsys):
main_exec(args) main_exec(args)
captured = capsys.readouterr() captured = capsys.readouterr()
assert mock.call_count == 1 assert mock.call_count == 1
with pytest.raises(SystemExit):
args = add_arguments(['--config', '/dev/null'])
main_exec(args)
assert log_has('Could not load config file /dev/null.', caplog)
args = add_arguments([
'--config',
'tests/testdata/testconfigs/main_test_config.json',
'whatever'
])
main_exec(args)
assert log_has('Command whatever not defined', caplog)